我想使用c#.net压缩图像 [英] i want to squeeze the image using c#.net

查看:94
本文介绍了我想使用c#.net压缩图像的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

朋友们,

我想缩小图像的大小,即减小图像的高度和宽度...

我有文件名(图像名),并已使用opendialog提取了该名称,然后使用以下语句openFileDialog1.FileName;

我已经尝试过以下编码,但无法压缩图像

Hi friends,

I want to squeeze the size of image i.e to reduce the height and width of image...

I have file name(image name) and I had extracted that name by using opendialog and then used the following statement openFileDialog1.FileName;

I have have tried the folowing coding but I''m not able to squeeze the image

string file = openFileDialog1.FileName;
               FileInfo f = new FileInfo(file);
               Image img = Image.FromFile(file);
               Bitmap b = new Bitmap(20,20);
               Graphics g = Graphics.FromImage((Image)b);
               g.InterpolationMode = InterpolationMode.HighQualityBicubic;
               g.DrawImage(img, 0, 0, 20,20);
               img.Save(file);



请帮我解决这个问题.
在此先感谢



please help me to solve this problem.
thanks in advance

推荐答案

创建所需大小的新Bitmap对象.

Graphics.FromImage将为新的位图创建一个图形对象,然后DrawImage将原始图像放置到新的位图上.

保存新的位图!

乔布斯很好.
Create a new Bitmap object of the required size.

Graphics.FromImage will create a graphic object for the new bitmap, then DrawImage to put the original image onto the new bitmap.

Save the new bitmap!

Jobs a good''un.


这篇关于我想使用c#.net压缩图像的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆