POST image for the web server on a Windows 8 phone

I have an application for Windows 8 that works very well, and now I want to write the same application for Windows Phone 8, but I get only a black image and not the correct image.

This is my image file upload code.

if ((_fileType == ".jpg" || _fileType == ".png" || _fileType == ".jpeg") && _fileSize < 3500000) { byte[] myPicArray = ConvertToBytes(_bmpFile); HttpClient httpClient = new HttpClient(); httpClient.BaseAddress = new Uri(MYURI); MultipartFormDataContent form = new MultipartFormDataContent(); HttpContent content = new ByteArrayContent(myPicArray); form.Add(content, "media", _randomStringFileName + _fileType); HttpResponseMessage response = await httpClient.PostAsync("upload.php", form); } 

and this is the code to convert my image to an array of bytes

 private byte[] ConvertToBytes(BitmapImage bitmapImage) { using (MemoryStream ms = new MemoryStream()) { WriteableBitmap btmMap = new WriteableBitmap (bitmapImage.PixelWidth, bitmapImage.PixelHeight); // write an image into the stream Extensions.SaveJpeg(btmMap, ms, bitmapImage.PixelWidth, bitmapImage.PixelHeight, 0, 100); return ms.ToArray(); } } 

Does anyone have an idea why I only get a black image and not an image? Image was selected by PhotoChooseTask.

+4
source share
1 answer

PhotoChooseTask already provides you with Stream, so you just need to use it (you cannot use BitMap yet, because it is still busy recording to the device and generating thumbnails, etc.)

  PhotoResult photoResult = e as PhotoResult; MemoryStream memoryStream = new MemoryStream(); photoResult.ChosenPhoto.CopyTo(memoryStream); byte[] myPicArray = memoryStream.ToArray(); 
+3
source

All Articles