Click here to Skip to main content
15,897,519 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
How to convert image to byte array in windows 8.1 store apps developing.

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


The above code is for windows phone 8.1 but i want it for windows 8.1 store app.
, How to convert please help me...

thanks.
Posted
Updated 18-Nov-14 0:26am
v2

1 solution

While I do not develop Win Store apps, a quick look at the documentation for 'SaveJpeg suggests you are missing arguments: [^].
C#
SaveJpeg(
this WriteableBitmap bitmap,
Stream targetStream,
int targetWidth,
int targetHeight,
int orientation,
int quality
)
It also "jumps out at me" that you create a memory stream and then do not do anything to get the image data into the stream.

Typical code to get Image contents as byte[] in System.Drawing.Image:
C#
MemoryStream ms = new MemoryStream();
YourImage.Save(ms,System.Drawing.Imaging.ImageFormat.Jpeg);
byte[] bAry = ms.ToArray();
 
Share this answer
 
Comments
SureshMarepalli 18-Nov-14 3:44am    
thanks for your answer , but in windows 8.1 system.drawing is not there.
BillWoodruff 18-Nov-14 8:15am    
Yes, I showed the code for System.Drawing.Imaging knowing it was not in 8.1 for store apps, just as an example of what code looks like that actually puts some information in a MemoryStream. Sorry if that was confusing.

However, 'SaveJpeg is an 8.1 store app Extension method, and if you don't have the arguments correct, then that's one reason your code won't work.

cheers, Bill

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900