我正在尝试制作一个可以接受图像字节 [] 的 Web 服务,并将其保存到 Web 服务器。代码由两部分组成,发送数据的客户端和获取数据的 Web 服务。尝试上传图像时出现以下错误: System.ServiceModel.FaultException`1[System.ServiceModel.ExceptionDetail]:GDI+ 中发生一般错误。
myImage 是一个 System.Drawing 图像。
private byte[] imageToByteArray(Image imageIn)
{
MemoryStream ms = new MemoryStream();
imageIn.Save(ms,ImageFormat.Png);
return ms.ToArray();
}
using (Something.ClientServiceClient client = new Something.ClientServiceClient())
{
client.Open();
client.uploadScreenShot(imageToByteArray(myImage));
}
网络服务如下所示:
public void uploadHofScreen( byte[] imgArray)
{
Image nImg = byteArrayToImage(imgArray);
Bitmap bitmap = new Bitmap(nImg);
saveJpeg("/1/test.jpg", bitmap, 85L);
}
private void saveJpeg(string path, Bitmap img, long quality)
{
EncoderParameter qualityParam = new EncoderParameter(System.Drawing.Imaging.Encoder.Quality, quality);
ImageCodecInfo jpegCodec = getEncoderInfo("image/jpeg");
if (jpegCodec == null)
return;
EncoderParameters encoderParams = new EncoderParameters(1);
encoderParams.Param[0] = qualityParam;
img.Save("XXXX" + path, jpegCodec, encoderParams);
}
private ImageCodecInfo getEncoderInfo(string mimeType)
{
ImageCodecInfo[] codecs = ImageCodecInfo.GetImageEncoders();
for (int i = 0; i < codecs.Length; i++)
if (codecs[i].MimeType == mimeType)
return codecs[i];
return null;
}
webconfig 和 appconfig 都有以下 readerQuotas:
<readerQuotas maxDepth="2147483647" maxStringContentLength="2147483647" maxArrayLength="2147483647" maxBytesPerRead="2147483647" maxNameTableCharCount="2147483647" />
有什么建议吗?