// Create source
BitmapImage myBitmapImage = new BitmapImage();
// BitmapImage.UriSource must be in a BeginInit/EndInit block
myBitmapImage.BeginInit();
myBitmapImage.UriSource = new Uri(@"C:\Water Lilies.jpg");
// To save significant application memory, set the DecodePixelWidth or
// DecodePixelHeight of the BitmapImage value of the image source to the desired
// height or width of the rendered image. If you don't do this, the application will
// cache the image as though it were rendered as its normal size rather then just
// the size that is displayed.
// Note: In order to preserve aspect ratio, set DecodePixelWidth
// or DecodePixelHeight but not both.
myBitmapImage.DecodePixelWidth = 200;
myBitmapImage.EndInit();
//
//when you are ready to render the BitmapImage, do:
imageThumb.Source = myBitmapImage;
4 回答
这是我不久前写的一种可能对你有帮助的方法 .
我传入原始图像二进制文件,并将图像大小调整为大约160px左右 .
希望能帮助到你!
您可以使用
InterpolationMode.HighQualityBicubic
创建合适的拇指位图如果您在后台线程中创建拇指,只需将它们保存到内存流中,然后您可以在请求时懒惰地使用它来创建
BitmapImage
:在检查MSDN后,我没有看到任何直接的方法来做到这一点,但也许你可以只是每隔这么多像素采样图像并将数据写入新图像,然后清理完整尺寸的图像 .
来自的C#示例:http://msdn.microsoft.com/en-us/library/ms748873.aspx
请注意DecodePixelWidth和DecodePixelHeight属性,以便以所需的缩小像素大小缓存图像 . 使用两者来拉伸图像以适合缩略图大小 .