减少像素数 [英] decrease the number of pixels
本文介绍了减少像素数的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
有人可以告诉我如何减少c#中的图像像素数.
can somebody tells me how to decrease the number of pixels of an image in c#
推荐答案
看看Image.GetThumbnailImage方法 [
Have a look at the Image.GetThumbnailImage Method[^] - it probably provides what you are looking for. Mind you, with that little info, it is difficult to tell! :laugh:
刚刚写了一个方法!
Just have written a method for it!
public static Image resizeImage(Image imgToResize, Size size)
{
int sourceWidth = imgToResize.Width;
int sourceHeight = imgToResize.Height;
float nPercent = 0;
float nPercentW = 0;
float nPercentH = 0;
nPercentW = ((float)size.Width / (float)sourceWidth);
nPercentH = ((float)size.Height / (float)sourceHeight);
if (nPercentH < nPercentW)
nPercent = nPercentH;
else
nPercent = nPercentW;
int destWidth = (int)(sourceWidth * nPercent);
int destHeight = (int)(sourceHeight * nPercent);
Bitmap b = new Bitmap(destWidth, destHeight);
Graphics g = Graphics.FromImage((Image)b);
g.InterpolationMode = InterpolationMode.HighQualityBicubic;
g.DrawImage(imgToResize, 0, 0, destWidth, destHeight);
g.Dispose();
return (Image)b;
}
例如:
example:
Image myNewImage = resizeImage(myImage, New Size(1000, 1000);
您现在拥有一张在原始图像的最长边上最多具有1000像素的图像.
为了保护您的图片,请使用
You now have an image this has maximum of 1000 pixles on the longest side of the original image.
To safe your image use
myNewImage.Save(NewFileName);
这篇关于减少像素数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文