Lia*_*mHT 4 c# asp.net azure azure-storage azure-storage-blobs
我正在使用内存流将System.Drawing.Bitmap编写到Azure存储.我有正确的凭据和一切蔚蓝的一面正确连线.我已经使用输入流成功地将图像上传到blob中,所以我认为这对于我如何使用memorystream对象一定是个问题.
看了一会儿后,我的问题的一般解决方案看起来是将内存流位置设置为0,但这对我没有用,而且一个空文件仍然保存到azure中.
我的代码是:
using (image)
{
System.IO.MemoryStream ms = new MemoryStream();
//create an encoder parameter for the image quality
EncoderParameter qualityParam = new EncoderParameter(System.Drawing.Imaging.Encoder.Quality, quality);
//get the jpeg codec
ImageCodecInfo imgCodec = ImageUtilities.GetEncoderInfo(CodecInfo);
//create a collection of all parameters that we will pass to the encoder
EncoderParameters encoderParams = new EncoderParameters(1);
//set the quality parameter for the codec
encoderParams.Param[0] = qualityParam;
//Move the pointer to the start of stream.
ms.Position = 0;
image.Save(ms, imgCodec, encoderParams);
blockBlob.UploadFromStream(ms);
}
Run Code Online (Sandbox Code Playgroud)
最后保存的图像元素中包含数据.在调试时保持正确的长度等,所以问题出现在上传步骤中
Gui*_*ume 12
保存图像后和上传之前,您必须回放内存流:
//...
//Move the pointer to the start of stream.
ms.Position = 0;
image.Save(ms, imgCodec, encoderParams);
//HERE !!!
ms.Position = 0;
blockBlob.UploadFromStream(ms);
}
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
3814 次 |
| 最近记录: |