none
Convert a Picture Taken by a camera into a byte array by resizing it. RRS feed

  • Question

  • I am currently developing an App which using the Local Database of the WP7.

    One of the features I wish to include is where the User can take a picture from the phone camera and store it for each record in the database.
    I have a byte[] array column in the database.

    I also am able to convert any WritableBitMap to a Byte array. However, since the photo taken by the phone camera has a resolution of atleast 2000 x 1000 pixels, I am unable to store the image into a byte array. I wish to resize the WriteableBitMap file to about 400 x 240 pixels.

    So could anyone help me with the code I am supposed to use in the CameraTaskCompleted event handler to resize the image taken to 400 x 240?
    Thanks.


    Tuesday, May 8, 2012 11:43 AM

Answers

  • This may not be the most efficient way to do this, but you can create a Image framework element with the dimensions that you want with the strettch optione set to Stretch.Uniform and the source as your original image source.  From that Image item, you can use the 
    WritableBitmap resizedBitMap = new WritableBitmap(imageItem, null);
    to as a new Bitmap that is of the size you desire.  From there, use the resizedBitMap.SaveJpeg() function to write the image to a memory stream that you can use to convert to a byte array.
    Tuesday, May 8, 2012 2:27 PM
  • Thanks.
    That could work. I also figured this way out.

    bitmapImage =

     

    PictureDecoder.DecodeJpeg(e.ChosenPhoto, 400, 240);
    The DecoderJpeg method lets you choose the maximum pixel width and height. This way, it resizes the image immediately after the cameratask picture is chosen. 

    Thanks anyway. :) 

     

    Monday, May 14, 2012 11:40 AM

All replies

  • This may not be the most efficient way to do this, but you can create a Image framework element with the dimensions that you want with the strettch optione set to Stretch.Uniform and the source as your original image source.  From that Image item, you can use the 
    WritableBitmap resizedBitMap = new WritableBitmap(imageItem, null);
    to as a new Bitmap that is of the size you desire.  From there, use the resizedBitMap.SaveJpeg() function to write the image to a memory stream that you can use to convert to a byte array.
    Tuesday, May 8, 2012 2:27 PM
  • Thanks.
    That could work. I also figured this way out.

    bitmapImage =

     

    PictureDecoder.DecodeJpeg(e.ChosenPhoto, 400, 240);
    The DecoderJpeg method lets you choose the maximum pixel width and height. This way, it resizes the image immediately after the cameratask picture is chosen. 

    Thanks anyway. :) 

     

    Monday, May 14, 2012 11:40 AM