【问题标题】:How can I convert WriteableBitmap to BitmapImage?如何将 WriteableBitmap 转换为 BitmapImage?
【发布时间】:2010-10-21 10:52:51
【问题描述】:
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 根本不显示。可以做些什么来让它发挥作用?

【问题讨论】:

    标签: c# silverlight silverlight-4.0 bitmapimage writeablebitmap


    【解决方案1】:
    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);
    }
    

    【讨论】:

    • WriteableBitmap 中没有 SaveJpeg
    • @Nayef:它是另一个命名空间中的extension method
    • 怎么用?我试图包含它,但我无法在 Silverlight 中包含它,知道吗?
    • @abatishchev 您的链接已损坏 - 这与您引用的 extension method 相同吗?在这种情况下,扩展类现在似乎只为 windows phone 平台构建
    【解决方案2】:

    你为什么不把ScaleTransform也应用到UIElement上呢?

    【讨论】:

      猜你喜欢
      • 2018-02-19
      • 1970-01-01
      • 1970-01-01
      • 2016-02-15
      • 2012-06-30
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多