【发布时间】:2013-08-13 03:00:49
【问题描述】:
所以我需要向一个返回图像的 PHP 页面发送请求,该图像不能直接使用 URL 读取(当然可以,但从技术上讲,它只包含图像数据,而不是以 .jpg 结尾的页面)...
因此我需要从响应中读取图像(返回页面给我的Content-Type: image/jpeg,它直接显示图像数据(就像您在记事本中打开图像时一样 - 由符号组成......)
如何才能将此图像数据转换为有效图像?
我尝试使用响应中的字节将它们转换为图像;使用这个:
private Bitmap ByteToImage(byte[] blob)
{
MemoryStream mStream = new MemoryStream();
byte[] pData = blob;
mStream.Write(pData, 0, Convert.ToInt32(pData.Length));
Bitmap bm = new Bitmap(mStream, false);
mStream.Dispose();
return bm;
}
和
byte[] imageBytes = Encoding.UTF8.GetBytes(post(imagelink, ""));
但这只会给我一个 ArgumentException。
【问题讨论】:
标签: c# image jpeg content-type