0

I am currently converting a Silverlight application into WPF. In my silverlight application I have the code

WriteableBitmap sceneBitmap = new WriteableBitmap(scene, new TranslateTransform() { Y = 10 });
WriteableBitmap newone = TimelineMainHelper.CropImage(sceneBitmap, 0, 0, sceneBitmap.PixelWidth, sceneBitmap.PixelHeight - 25);
newone.Invalidate();
img.Source = newone;

Where scene is a control. When putting this into WPF there are no overloads for the writeablebitmap class which take UIElement and Transform as the parameters. Firstly I was wondering why this is? and secondly I was wondering if there was a way getting a control to a writeablebitmap

JKennedy
  • 18,150
  • 17
  • 114
  • 198

1 Answers1

1

Instead you will want to use RenderTargetBitmap and CroppedBitmap I believe:

RenderTargetBitmap rtb = new RenderTargetBitmap((int)scene.ActualWidth, (int)scene.ActualHeight, 96, 96, System.Windows.Media.PixelFormats.Pbgra32);
rtb.Render(this.sceneBitmap);

CroppedBitmap crop = new CroppedBitmap(sceneBitmap, new Int32Rect(0, 0, (int)sceneBitmap.ActualWidth, (int)sceneBitmap.ActualHeight));

Then you can do something like:

System.Windows.Controls.Image img = new Image();
img.Source = crop;

And go from there.

Disclaimer:

You may need to use different overloads and what not to do exactly what you wish. I just took a shot guessing what parameters to pass given your snippet.

Kcvin
  • 5,073
  • 2
  • 32
  • 54
  • @kcvin I have an Image with horizontal alignment, width, height etc. set & then I want to apply RotateTransform on that and convert in into a writableBitmap. Earlier, we used to have WriteableBitmap function with UIlelement & tranform but now it's not there. Can you please hep me with this? – hellodear Sep 13 '17 at 14:22