如何将WriteableBitmap转换为BitmapImage?

12
BitmapImage bitmapImage = new BitmapImage(new Uri("arka_projects_as_logo.png", UriKind.Relative));
Image uiElement = new Image() { Source = bitmapImage };
ScaleTransform t = new ScaleTransform() { ScaleX = 0.2, ScaleY = 0.2 };
WriteableBitmap writeableBitmap = new WriteableBitmap(uiElement,t);

我希望将这个转换结果(writeableBitmap)插入到 System.Windows.Controls.Image 中。当我这样做时:
Image arkaImage = new Image() { Source = writeableBitmap };

arkaImage 没有显示。有什么方法可以让它工作?

2个回答

10
WriteableBitmap wb = ..
using (MemoryStream ms = new MemoryStream())
{
    wb.SaveJpeg(ms, (int)image1.Width, (int)image1.Height, 0, 100);
    BitmapImage bmp = new BitmapImage();
    bmp.SetSource(ms);
}

3
WriteableBitmap中没有SaveJpeg方法。 - Nayef
@Nayef:这是另一个命名空间中的扩展方法 - abatishchev
怎么使用它?我试图在Silverlight中包含它,但是我做不到,有什么想法吗? - Nayef
@abatishchev,你的链接无效了 - 这是你所引用的相同扩展方法吗?如果是的话,现在似乎只有为Windows Phone平台构建扩展类。 - stoves

2
为什么不将 ScaleTransform 应用到 UIElement 上呢?

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接