private System.Drawing.Bitmap ResizeBMP(System.Drawing.Bitmap source_bmp,int new_width,int new_height)
{
float x_rate=(float)source_bmp.Width/(float)new_width;
float y_rate=(float)source_bmp.Height/(float)new_height;
System.Drawing.Bitmap cache_bmps=new Bitmap(new_width,new_height,PixelFormat.Format24bppRgb);
for(int cy=0;cy<new_height;cy++)
{
for(int cx=0;cx<new_width;cx++)
{
cache_bmps.SetPixel(cx,cy,source_bmp.GetPixel((int)((cx+1)*x_rate-1),(int)((cy+1)*y_rate-1)));
}
}
return cache_bmps;
}
输入一个图片,获得转换成为指定大小的图片
本文介绍了一种基于像素映射的图片缩放方法,通过计算原始图片与目标尺寸的比例关系,实现了图片的等比缩放。该方法适用于需要调整图片大小的应用场景。

被折叠的 条评论
为什么被折叠?



