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

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?

Dave Clemmer
  • 3,741
  • 12
  • 49
  • 72
Sergey
  • 47,222
  • 25
  • 87
  • 129

2 Answers2

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);
}
abatishchev
  • 98,240
  • 88
  • 296
  • 433
  • 3
    there is no SaveJpeg in WriteableBitmap – Nayef May 19 '15 at 12:08
  • @Nayef: it's an [extension method](https://msdn.microsoft.com/en-uS/office/office365/system.windows.media.imaging.extensions.savejpeg%28v=vs.105%29.aspx) in another namespace. – abatishchev May 19 '15 at 15:36
  • How to use it? I tried to include it but I couldn't do in Silverlight, any idea? – Nayef May 21 '15 at 06:24
  • @abatishchev your link is broken - is this the same [extension method](https://msdn.microsoft.com/en-us/library/windows/apps/system.windows.media.imaging.extensions.savejpeg) you were referencing? in which case the extensions class only build for windows phone platforms now it seems – stoves Jul 12 '16 at 19:47
2

Why don't you just apply the ScaleTransform to the UIElement as well?

Dave Clemmer
  • 3,741
  • 12
  • 49
  • 72
Mads Lee Jensen
  • 4,570
  • 5
  • 36
  • 53