Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
465 views
in Technique[技术] by (71.8m points)

c# - How can I convert WriteableBitmap to BitmapImage?

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

I want to insert the result of this conversions (writeableBitmap) into System.Windows.Controls.Image. When I do this:

Image arkaImage = new Image() { Source = writeableBitmap };

arkaImage isn't shown at all. What can be done to make it work?

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)
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);
}

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...