我有一个运行良好的 Windows 8 应用程序,现在我想为 Windows Phone 8 编写相同的应用程序,但我只得到一个黑色图像而不是正确的图像。
这是我上传图片文件的代码
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);
}
这是将我的图像转换为字节数组的代码
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();
}
}
有人知道为什么我只得到黑色图像而不是正确的图像吗?图像由 PhotoChooseTask 选择。