how to convert panandzoomimage to byte[]

4 posts, 0 answers
  1. Jonathan
    Jonathan avatar
    23 posts
    Member since:
    Feb 2013

    Posted 14 Feb 2013 Link to this post

    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
  2. Victor
    Admin
    Victor avatar
    1351 posts

    Posted 15 Feb 2013 Link to this post

    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.
  3. DevCraft banner
  4. Jonathan
    Jonathan avatar
    23 posts
    Member since:
    Feb 2013

    Posted 15 Feb 2013 Link to this post

    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

  5. Victor
    Admin
    Victor avatar
    1351 posts

    Posted 19 Feb 2013 Link to this post

    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.
Back to Top