如何将WriteableBitmap转换为BitmapImage?

时间:2010-10-21 10:52:52

标签: c# silverlight silverlight-4.0 bitmapimage writeablebitmap

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 个答案:

答案 0 :(得分:11)

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);
}

答案 1 :(得分:2)

为什么不将ScaleTransform同时应用于UIElement