将图像存储在c#中的变量中?请帮我... [英] store image in a variable in c#? Please Help me...

查看:52
本文介绍了将图像存储在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


这篇关于将图像存储在c#中的变量中?请帮我...的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆