您可以使用以下命令创建像样的拇指位图InterpolationMode.HighQualityBicubic
Bitmap bitmap = ...
Bitmap thumbBitmap = new System.Drawing.Bitmap(thumbWidth, thumbHeight);
using (Graphics g = Graphics.FromImage(thumbBitmap))
{
g.InterpolationMode = InterpolationMode.HighQualityBicubic;
g.DrawImage(bitmap, 0, 0, thumbWidth, thumbHeight);
}
Run Code Online (Sandbox Code Playgroud)
如果您在后台线程中创建拇指,只需将它们保存到内存流中,然后您可以在BitmapImage
请求时懒惰地使用它来创建:
_ms = new MemoryStream();
thumbBitmap.Save(_ms, ImageFormat.Png);
_ms.Position = 0;
ImageLoaded = true;
//thumb image property of this class, use in binding
public BitmapImage ThumbImage
{
get
{
if (_thumbImage == null && ImageLoaded)
{
BitmapImage bi = new BitmapImage();
bi.BeginInit();
bi.StreamSource = _ms;
bi.EndInit();
_thumbImage = bi;
}
return _thumbImage;
}
}
Run Code Online (Sandbox Code Playgroud)