Bitmap这几行代码错在哪里了????????

zhaozhe123 2010-09-11 10:00:35
Bitmap oldPic = new Bitmap(路径);
int intHeight = 40;
int intWidth = (intHeight / oldPic.Height) * oldPic.Width;
Bitmap newPic = new Bitmap(oldPic,intWidth,intHeight);
newPic.Save(新路径);

如果把int intWidth = (intHeight / oldPic.Height) * oldPic.Width;
改成int intWidth = 50; 就没有任何问题

把代码改成
Bitmap oldPic = new Bitmap(路径);
int intHeight = 40;
int oldHeight = Convert.ToInt32(oldPic.Height);
int oldWidth = Convert.ToInt32(oldPic.Width);
int intWidth = (intHeight / oldHeight) * oldWidth; 或Convert.ToInt32( (intHeight / oldHeight) * oldWidth);
Bitmap newPic = new Bitmap(oldPic,intWidth,intHeight);
newPic.Save(新路径);

还是显示Bitmap newPic = new Bitmap(oldPic,intWidth,intHeight);这行代码的参数无效
...全文
148 6 打赏 收藏 转发到动态 举报
写回复
用AI写文章
6 条回复
切换为时间正序
请发表友善的回复…
发表回复
Peter200694013 2010-09-12
  • 打赏
  • 举报
回复
断点调试,看看intWidth,intHeight的值,是否不在范围
zhaozhe123 2010-09-12
  • 打赏
  • 举报
回复
int intWidth = (intHeight / oldPic.Height) * oldPic.Width;

改成 float ft = (intHeight / oldPic.Height) * oldPic.Width;
然后 Response.Write(ft) 结果还是0

我基础知识不太好,是不是数据格式的问题?
zhaozhe123 2010-09-12
  • 打赏
  • 举报
回复
oldpic.height=416
oldpic.width=540 调式自动窗口中看到的

这两个值也没问题啊
zhaozhe123 2010-09-12
  • 打赏
  • 举报
回复
调试看到intWidth值等于0,又如何处理呢????
wuyq11 2010-09-11
  • 打赏
  • 举报
回复
int intWidth = (intHeight / oldHeight) * oldWidth设置断点查看数据
q107770540 2010-09-11
  • 打赏
  • 举报
回复
int intWidth = (intHeight / oldPic.Height) * oldPic.Width;
在此句处加上断点
调试查看intWidth得到值是多少

62,272

社区成员

发帖
与我相关
我的任务
社区描述
.NET技术交流专区
javascript云原生 企业社区
社区管理员
  • ASP.NET
  • .Net开发者社区
  • R小R
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告

.NET 社区是一个围绕开源 .NET 的开放、热情、创新、包容的技术社区。社区致力于为广大 .NET 爱好者提供一个良好的知识共享、协同互助的 .NET 技术交流环境。我们尊重不同意见,支持健康理性的辩论和互动,反对歧视和攻击。

希望和大家一起共同营造一个活跃、友好的社区氛围。

试试用AI创作助手写篇文章吧