2014-09-30 40 views
1

怎麼能認爲這個代碼在這裏做轉換的圖像?如何從文件夾中定義的圖像是在有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. 

} 
+0

我很抱歉,但我不明白的問題,所有..不知道該問什麼.. – 2014-09-30 07:38:43

+0

我問我怎麼可以添加在這個圖像,我怎麼能在形式上顯示圖像? – BuschJoe 2014-09-30 07:41:09

回答

0

如果你想從一個文件中加載圖像,只需使用:

Image img = Image.FromFile("C:\mypath\myimage.png"); //load the file as image 
pictureBox1.Image = img; //use the image how you like 

你並不需要經過轉換的過程圖像信息轉化爲Byte[],除非你的意思是存儲在某個地方,比如在數據庫中。

+0

我有大約400個圖像和400所形成這麼多的圖片,我可以以某種形式與不同的按鈕綁定400倍的圖像? – BuschJoe 2014-09-30 11:32:42

+0

當然。你爲什麼想要?爲什麼這些400張圖片沒有資源編譯到您的項目中? – DonBoitnott 2014-09-30 11:37:39

+0

如果我將所有資源添加到資源中,應用程序崩潰...! – BuschJoe 2014-10-01 06:44:54

相關問題