C# 改变图片width height dpi 方法
2010-04-13 14:47
197 查看
if (this.pbMain.Image.VerticalResolution < 200 || this.pbMain.Image.HorizontalResolution < 200)
{
//System.Drawing.Image img = System.Drawing.Image.FromHbitmap(((Bitmap)this.images[0]).GetHbitmap());
//float x = img.VerticalResolution;
//float y = img.HorizontalResolution;
int width = ((Bitmap)this.images[0]).Width;
int height = ((Bitmap)this.images[0]).Height;
if (height > width)
{
height = 2338;
width = 1653;
}
else if (width > height)
{
height = 1653;
width = 2338;
}
Bitmap bmpSource = new Bitmap(((Bitmap)this.images[0]), width, height);
//Bitmap bmpSource = new Bitmap(((Bitmap)this.images[0]));
int iSourceWidth = bmpSource.Width;
int iSourceHeight = bmpSource.Height;
float fSourceHorResolution = bmpSource.HorizontalResolution;
float fSourceVerResolution = bmpSource.VerticalResolution;
//图象dpi
float fTargetHorResolution = 200;
float fTargetVerResolution = 200;
Bitmap bmpTarget = new Bitmap(width, height);
Graphics g = Graphics.FromImage(bmpTarget);
g.DrawImage(bmpSource, 0, 0, iSourceWidth, iSourceHeight);
bmpTarget.SetResolution(fTargetHorResolution, fTargetVerResolution);
bmpTarget = TiffManager.KiSharpen(bmpTarget, (float)0.7);
bmpTarget = TiffManager.ConvertTo1bbpIndexed(bmpTarget, (float)0.8);
bmpTarget.Save(filename, info, ep);
}
{
//System.Drawing.Image img = System.Drawing.Image.FromHbitmap(((Bitmap)this.images[0]).GetHbitmap());
//float x = img.VerticalResolution;
//float y = img.HorizontalResolution;
int width = ((Bitmap)this.images[0]).Width;
int height = ((Bitmap)this.images[0]).Height;
if (height > width)
{
height = 2338;
width = 1653;
}
else if (width > height)
{
height = 1653;
width = 2338;
}
Bitmap bmpSource = new Bitmap(((Bitmap)this.images[0]), width, height);
//Bitmap bmpSource = new Bitmap(((Bitmap)this.images[0]));
int iSourceWidth = bmpSource.Width;
int iSourceHeight = bmpSource.Height;
float fSourceHorResolution = bmpSource.HorizontalResolution;
float fSourceVerResolution = bmpSource.VerticalResolution;
//图象dpi
float fTargetHorResolution = 200;
float fTargetVerResolution = 200;
Bitmap bmpTarget = new Bitmap(width, height);
Graphics g = Graphics.FromImage(bmpTarget);
g.DrawImage(bmpSource, 0, 0, iSourceWidth, iSourceHeight);
bmpTarget.SetResolution(fTargetHorResolution, fTargetVerResolution);
bmpTarget = TiffManager.KiSharpen(bmpTarget, (float)0.7);
bmpTarget = TiffManager.ConvertTo1bbpIndexed(bmpTarget, (float)0.8);
bmpTarget.Save(filename, info, ep);
}
相关文章推荐
- 常量,字段,构造方法 调试 ms 源代码 一个C#二维码图片识别的Demo 近期ASP.NET问题汇总及对应的解决办法 c# chart控件柱状图,改变柱子宽度 使用C#创建Windows服务 C#服务端判断客户端socket是否已断开的方法 线程 线程池 Task .NET 单元测试的利剑——模拟框架Moq
- C#操作word的一些基本方法(word打印,插入文件,插入图片,定位页眉页脚,去掉横线)
- C#实现图片压缩方法
- UITableview改变Width和Height之后重新调用代理方法的总结
- 最简单的方法来压缩图片,改变图片大小
- 上传图片并显示缩略图的最简单方法(c#)
- tableviewcell imageview改变图片大小方法
- C# 将字节流转换为图片的实例方法(转)
- C# 判断图形文件(GIF,JPG,PNG)的图片格式的方法
- C#实现图片叠加,图片上嵌入文字,文字生成图片的方法
- C#向Excel报表中插入图片的2种方法【转】
- C# WinForm 上传图片,文件到服务器的方法Uploader.ashx
- C# 使用资源管理器中 resources文件中图片方法
- C# 改变图片尺寸(压缩),Image Resize
- C# 改变无边框窗体尺寸大小的方法
- Visual Studio 2017中使用正则修改部分内容 如何使用ILAsm与ILDasm修改.Net exe(dll)文件 C#学习-图解教程(1):格式化数字字符串 小程序开发之图片转Base64(C#、.Net) jquery遍历table为每一个单元格取值及赋值 。net加密解密相关方法 .net关于坐标之间一些简单操作
- c#一种简单快速改变窗体风格和肤色的方法源码及其控件
- C#操作word的一些基本方法(word打印,插入文件,插入图片,定位页眉页脚,去掉横线)
- C# Selenium with PhantomJSDriver get image width and height (获取图片的长和高)
- 【转】解决WPF图片模糊最佳方法(绑定PixelWidth与PixelHeight)