将图像存储在c#中的变量中?请帮我...
问题描述:
请帮我解决这个问题..
Please Help me With this Problem..
答
是的,你可以这样做
以下代码将转换为字节数组中的图像
yes you can do like this
below code will convert image in byte array
public byte[] imageToByteArray(System.Drawing.Image imageIn)
{
MemoryStream ms = new MemoryStream();
imageIn.Save(ms,System.Drawing.Imaging.ImageFormat.Gif);
return ms.ToArray();
}
您可以通过以下功能将字节数组转换回图像
and you can convert back byte array to image by below function
public Image byteArrayToImage(byte[] byteArrayIn)
{
MemoryStream ms = new MemoryStream(byteArrayIn);
Image returnImage = Image.FromStream(ms);
return returnImage;
}
因此,通过将图像转换为字节数组,您可以将图像存储在内存变量中,而不是在需要图像时你可以将字节数组转换为图像
So by converting image to byte array you can store your image in memory variable and than when you need image back you can convert byte array to image