我需要将图像转换为Byte数组,因为我必须上传到服务器,看过很多文章,但我无法理解机智已经完成,请原谅我,如果你认为我的问题在这里被问到了论坛
答案 0 :(得分:1)
如果您有一个WriteableBitmap,例如名为LoadedPhoto,您可以尝试:
using (MemoryStream ms = new MemoryStream()
{
LoadedPhoto.SaveJpeg(ms, LoadedPhoto.PixelWidth, LoadedPhoto.PixelHeight, 0, 95);
ms.Seek(0, 0);
byte[] data = new byte[ms.Length];
ms.Read(data, 0, data.Length);
ms.Close();
}
如果您正在使用CodePlex的WriteableBitmapEx库,它也可以转换为字节数组 http://writeablebitmapex.codeplex.com/
答案 1 :(得分:0)
我认为它是一个位图(但它适用于所有图像类型):
System.Drawing.Bitmap bmp = GetYourImage();
System.IO.MemoryStream stream = new System.IO.MemoryStream();
bmp.Save(stream, System.Drawing.Imaging.ImageFormat.Bmp);
stream.Position = 0;
byte[] data = stream.ToArray();