none
RenderTargetBitmap怎么换为BitmapImage RRS feed

答案

  • 你好,

    请参考下面的代码:

                RenderTargetBitmap bmpRen = new RenderTargetBitmap(500, 350, 96, 96, PixelFormats.Pbgra32);
                bmpRen.Render(visual);
    
                BitmapEncoder bitmapEncoder = new BmpBitmapEncoder();
                BitmapImage bitmapImage = new BitmapImage();
                using (var stream = new MemoryStream())
                {
                    bitmapEncoder.Save(stream);
                    stream.Seek(0, SeekOrigin.Begin);
    
                    bitmapImage.BeginInit();
                    bitmapImage.CacheOption = BitmapCacheOption.OnLoad;
                    bitmapImage.StreamSource = stream;
                    bitmapImage.EndInit();
                }
    

    这里有一个类似的帖子,

    http://stackoverflow.com/questions/13987408/convert-rendertargetbitmap-to-bitmapimage

    谢谢!


    We are trying to better understand customer views on social support experience, so your participation in this interview project would be greatly appreciated if you have time. Thanks for helping make community forums a great place.
    Click HERE to participate the survey.

    • 已标记为答案 skczjun 2014年3月25日 5:10
    2014年3月25日 2:52
    版主