如何使用此加密代码在表单中添加图像链接
本文关键字:添加 图像 链接 表单 何使用 加密 代码 | 更新日期: 2023-09-27 18:24:59
这个代码应该如何在这里转换图像?我如何从bin文件夹中的文件夹定义图像?有人能帮我解决这个问题吗?我有20张照片和20张表格。。。
private static byte[] ConvertImageToByteArray(System.Drawing.Image imageToConvert,
ImageFormat formatOfImage)
{
byte[] Ret;
try
{
using (MemoryStream ms = new MemoryStream())
{
imageToConvert.Save(ms,formatOfImage);
Ret = ms.ToArray();
}
}
catch (Exception) { throw;}
return Ret;
}
//When you are ready to convert the byte array back
//to an image, you can include the following code
//in your method.
System.Drawing.Image newImage;
using (MemoryStream ms = new MemoryStream(myByteArray,0,myByteArray.Length))
{
ms.Write(myByteArray,0,myByteArray.Length);
newImage = Image.FromStream(ms,true);
// work with image here.
// You'll need to keep the MemoryStream open for
// as long as you want to work with your new image.
}
如果您想从文件加载图像,只需使用:
Image img = Image.FromFile("C:'mypath'myimage.png"); //load the file as image
pictureBox1.Image = img; //use the image how you like
您不需要经历将图像信息转换为Byte[]
的过程,除非您打算将其存储在某个地方,例如数据库中。