I was messing with a listbox control for my windows phone app and needed to convert a series
of bitmap images. Found this piece of code to convert the object. Now I should be able to
use my httppost class to pass the image as a parameter.
public static byte[] ConvertToBytes(this BitmapImage bitmapImage)
{
byte[] data = null;
using (MemoryStream stream = new MemoryStream())
{
WriteableBitmap wBitmap = new WriteableBitmap(bitmapImage);
wBitmap.SaveJpeg(stream, wBitmap.PixelWidth, wBitmap.PixelHeight, 0, 100);
stream.Seek(0, SeekOrigin.Begin);
data = stream.GetBuffer();
}
return data;
}
Source:
http://stackoverflow.com/questions/4732807/conversion-of-bitmapimage-to-byte-array
No comments:
Post a Comment