如何改变位图的dpi和大小,我的代码总是异常报出(GDI+)

ladofwind 2010-04-06 03:08:17
//add by ladofwind,change bitmap size and resolution
Bitmap bmpSource = new Bitmap(((Bitmap)this.images[0]), 1653, 2338);
int iSourceWidth = bmpSource.Width;
int iSourceHeight = bmpSource.Height;
float fSourceHorResolution = bmpSource.HorizontalResolution;
float fSourceVerResolution = bmpSource.VerticalResolution;
//dpi reset
float fTargetHorResolution = 200;
float fTargetVerResolution = 200;
Bitmap bmpTarget = new Bitmap(1653, 2338);
Graphics g = Graphics.FromImage(bmpTarget);
g.DrawImage(bmpSource, 0, 0, iSourceWidth, iSourceHeight);
bmpTarget.SetResolution(fTargetHorResolution, fTargetVerResolution);

ImageCodecInfo info = GetEncoderInfo("image/tiff");
Encoder enc = Encoder.SaveFlag;
EncoderParameters ep = null;
if (this.pbMain.Image.PixelFormat == PixelFormat.Format1bppIndexed) //G4 compression
{
ep = new EncoderParameters(3);
ep.Param[0] = new EncoderParameter(Encoder.Compression, (long)EncoderValue.CompressionCCITT4);
ep.Param[1] = new EncoderParameter(Encoder.Quality, 0L);//
ep.Param[2] = new EncoderParameter(Encoder.ColorDepth, 1L); // black/white
}


bmpTarget.Save(filename,info,ep); // exception thrown


...全文
183 5 打赏 收藏 转发到动态 举报
AI 作业
写回复
用AI写文章
5 条回复
切换为时间正序
请发表友善的回复…
发表回复
junwenwang 2010-06-14
  • 打赏
  • 举报
回复
而且没有delete bmpSource
junwenwang 2010-06-14
  • 打赏
  • 举报
回复
保存的参数加上引用符
ladofwind 2010-04-08
  • 打赏
  • 举报
回复
还没搞定
ladofwind 2010-04-07
  • 打赏
  • 举报
回复
没人会吗, 其实就是想把一个bmp的图,改变下dpi和width ,height 然后用G4压缩一下成tif图片,总报错

111,092

社区成员

发帖
与我相关
我的任务
社区描述
.NET技术 C#
社区管理员
  • C#
  • AIGC Browser
  • by_封爱
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告

让您成为最强悍的C#开发者

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