C# 如何使用此加密代码在表单中添加图像链接?

C# 如何使用此加密代码在表单中添加图像链接?,c#,image,winforms,encryption,C#,Image,Winforms,Encryption,这段代码如何在这里转换图像?我如何定义bin文件夹ch/1.jpg中的文件夹中的图像有人能帮我解决这个问题吗? 我有20张照片和20张表格 private static byte[] ConvertImageToByteArray(System.Drawing.Image imageToConvert, ImageFormat formatOfImage) { byte[] Ret; try { using (MemoryStream ms = new MemoryStream(

这段代码如何在这里转换图像?我如何定义bin文件夹ch/1.jpg中的文件夹中的图像有人能帮我解决这个问题吗? 我有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

您不需要经历将图像信息转换为字节[]的过程,除非您打算将其存储在某个位置,例如数据库中。

对不起,我根本不理解这个问题。。不知道问题是什么..我在问我如何在这里添加图像以及如何在表单中显示图像?我有这么多图像,大约400个图像和400个表单,我可以用不同的按钮在一个表单中绑定400个图像吗?当然可以。你为什么要这么做?为什么这400个图像不是编译到您的项目中的资源?如果我将所有图像都添加到资源中,应用程序将崩溃。。。!