winform求高速缩略图算法!(相机照片质量很高要去速度)
相机的照片提取缩略图 质量太高所以凡是用自带加载的话效率根本上不去
现在求高手想个办法如何高速生成缩略图(质量可无视)最好是微软打印向导生成缩略图的速度请高手帮帮忙谢谢!
[解决办法]
private Bitmap GetThumbnailImage(string s_FilePath, int x, int y)
{
using (Bitmap OriginalMap = new Bitmap(s_FilePath))
{
Bitmap Map = new Bitmap(x, y, PixelFormat.Format24bppRgb);
Rectangle Mrect = new Rectangle(0, 0, x, y);
BitmapData MbmpData = Map.LockBits(Mrect, ImageLockMode.ReadWrite, Map.PixelFormat);
int x_Width = OriginalMap.Width;
int y_Height = OriginalMap.Height;
Rectangle rect = new Rectangle(0, 0, x_Width, y_Height);
BitmapData bmpData = OriginalMap.LockBits(rect, ImageLockMode.ReadWrite, OriginalMap.PixelFormat);
int stribe = bmpData.Stride;
int Mstribe = MbmpData.Stride;
unsafe
{
try
{
byte* ptr = (byte*)(bmpData.Scan0);
byte* Mptr = (byte*)(MbmpData.Scan0);
for (int i = 0; i < y_Height; i++)
{
for (int j = 0; j < x_Width; j++)
{
int x_zoom = (int)x * j / x_Width;
int y_zoom = (int)y * i / y_Height;
Mptr[y_zoom * Mstribe + x_zoom * 3] = ptr[0];
Mptr[y_zoom * Mstribe + x_zoom * 3 + 1] = ptr[1];
Mptr[y_zoom * Mstribe + x_zoom * 3 + 2] = ptr[2];
ptr += 3;
}
ptr += stribe - x_Width * 3;
}
OriginalMap.UnlockBits(bmpData);
Map.UnlockBits(MbmpData);
}
catch (Exception ex)
{
MessageBox.Show(ex.Message, "Information");
}
}
return Map;
}
}
随便写了下,试试效果如何,自己调试