This is a migrated thread and some comments may be shown as answers.

how to convert panandzoomimage to byte[]

3 Answers 148 Views
PanAndZoomImage
This is a migrated thread and some comments may be shown as answers.
This question is locked. New answers and comments are not allowed.
Jonathan
Top achievements
Rank 1
Jonathan asked on 15 Feb 2013, 04:41 AM
Hello I'm trying to save a panandzoomimage to the windows phone picture folder by doing:
MemoryStream ms = new MemoryStream();
                WriteableBitmap wb = new WriteableBitmap(myPanAndZoomImage);
                wb.SaveJpeg(ms, myPanAndZoomImage.ActualWidth, myPanAndZoomImage.ActualHeight, 0, 100);

however I can't cast the zoomImage to (Image) or even (BitmapImage) so that wb will recognize it.  Are there any other methods to save, or convert to a byte[] to save?

thanks,
Jon

3 Answers, 1 is accepted

Sort by
0
Victor
Telerik team
answered on 15 Feb 2013, 08:22 AM
Hello Jonathan,

You should be able to capture PanAndZoomImage with a writeable bitmap. Any framework element can be converted to a byte array this way. You need to invalidate the WB after you create it in order for it to render the element you provided in its constructor. Then, when its Pixels array it created and populated, you can save it using the SaveJpeg method.

Kind regards,
Victor
the Telerik team
Have a suggestion or face a problem - you can use the Ideas & Feedback portal to submit ideas, feedback and vote for them.
0
Jonathan
Top achievements
Rank 1
answered on 15 Feb 2013, 04:00 PM
Hi Victor, thanks for the response.  Could you explain more about how I should be able to capture the PAZI with a writabelBitmap?
I thought this line would work:

WriteableBitmap wb = new WriteableBitmap(myPanAndZoomImage);

but I guess not?
Error    7    Argument 1: cannot convert from 'Telerik.Windows.Controls.SlideView.PanAndZoomImage' to 'System.Windows.Media.Imaging.BitmapSource'   

Or am I missing a conversion?

thanks,

Jon

0
Victor
Telerik team
answered on 19 Feb 2013, 11:44 AM
Hi Jonathan,

You should create your bitmap with the size of your pan and zoom image. You can also create it with the pan and zoom image and a null render transform. For example:

WriteableBitmap bitmap = new WriteableBitmap(panZoom, null);
bitmap.Invalidate();
Note that your pan and zoom image needs to be rendered before this is done.

Once this executes your bitmap's Pixels property will contain the rendered image.

If you need to get the bytes for each pixel, you can iterate over the Pixels array and call BitConverter.GetBytes() for each pixel. The byte array returned from get bytes is in the RGBA format. The first byte is red, second is green etc.

Kind regards,
Victor
the Telerik team
Have a suggestion or face a problem - you can use the Ideas & Feedback portal to submit ideas, feedback and vote for them.
Tags
PanAndZoomImage
Asked by
Jonathan
Top achievements
Rank 1
Answers by
Victor
Telerik team
Jonathan
Top achievements
Rank 1
Share this question
or