Convert image to byte array on Windows Phone 7 No

2020-04-19 09:01发布

问题:

Byte[] result = (Byte[])new ImageConverter().ConvertTo(img1, typeof(Byte[]));

//I cant use Image Converter add Image Class ? Drawing dll 

MemoryStream ms = new MemoryStream();

img1.Save(ms, System.Drawing.Imaging.ImageFormat.Gif);

return ms.ToArray();

//Cannot see System.Drawing dll and there is no  sth like Drawing.Imaging... 

Is there any other option rather than adding dll from the out source(I mean I ll copy it and then add it as an external dll )? My project is in windows 7 phone application and can not see Drwaing.dll stj like that

Thanks

回答1:

First there is no system.drawing in WP7.

You can do something like this:

MemoryStream ms = new MemoryStream();
WriteableBitmap wb = new WriteableBitmap(myimage);
wb.SaveJpeg(ms, myimage.PixelWidth, myimage.PixelHeight, 0, 100);
byte [] imageBytes = ms.ToArray();