Reputation: 165
How to send image as bytes stream to service?
By using belowcode i am binding the Url as image to image control.how to send it as bytes stream again to service?
please help me...
enter code here
string userimage="http://{ipadress}/sample.jpg";
Uri uri = new Uri(userImage, UriKind.Absolute);
image2.Source = new BitmapImage(uri);
Upvotes: 1
Views: 2203
Reputation: 9730
To convert above image to a bytearray you can try:
MemoryStream ms = new MemoryStream();
image2.Source.Save(ms,System.Drawing.Imaging.ImageFormat.Jpeg);
byte[] imageBytes = ms.ToArray();
EDIT:
If the above code doesn't give the desired results you can try:
WriteableBitmap bmp = new WriteableBitmap((BitmapSource)image2.Source);
byte[] byteArray;
using (MemoryStream stream = new MemoryStream()) {
bmp.SaveJpeg(stream, bmp.PixelWidth, bmp.PixelHeight, 0, 100);
byteArray = stream.ToArray();
}
You need to include the Microsoft.Phone
namespace for SaveJpeg
to work.
Upvotes: 4