loading an image in picturebox from database

EDN Admin

Well-known member
Joined
Aug 7, 2010
Messages
12,794
Location
In the Machine
<p style="margin-bottom:0in; margin-bottom:.0001pt; line-height:normal <span style="font-size:10.0pt; font-family:Times New Roman,serif <br/>

<span style="font-family:Times New Roman,serif ive tried the following code for loading an image in picturebox from database. but everytime , i get an error like Parameter not valid<br/>

<p style="margin-bottom:0in; margin-bottom:.0001pt; line-height:normal <br/>

<p style="margin-bottom:0in; margin-bottom:.0001pt; line-height:normal <span style="font-size:10.0pt; font-family:Times New Roman,serif buttonSave()
<p style="margin-bottom:0in; margin-bottom:.0001pt; line-height:normal <span style="font-size:10.0pt; font-family:Times New Roman,serif <span>
{
<p style="margin-bottom:0in; margin-bottom:.0001pt; line-height:normal <span style="font-size:10.0pt; font-family:Times New Roman,serif <span>
.......
<p style="margin-bottom:0in; margin-bottom:.0001pt; line-height:normal <span style="font-size:10.0pt; font-family:Times New Roman,serif <span>
.......
<p style="margin-bottom:0in; margin-bottom:.0001pt; line-height:normal <span style="font-size:10.0pt; font-family:Times New Roman,serif <span>
img = Image.FromFile(strFileName);
<p style="margin-bottom:0in; margin-bottom:.0001pt; line-height:normal <span style="font-size:10.0pt; font-family:Times New Roman,serif <span>
byte[] byteImg = ImageToByteArray(img);
<p style="margin-bottom:0in; margin-bottom:.0001pt; line-height:normal <span style="font-size:10.0pt; font-family:Times New Roman,serif <span>
objEmp.Picture = byteImg;
<p style="margin-bottom:0in; margin-bottom:.0001pt; line-height:normal <span style="font-size:10.0pt; font-family:Times New Roman,serif <span>
.......
<p style="margin-bottom:0in; margin-bottom:.0001pt; line-height:normal <span style="font-size:10.0pt; font-family:Times New Roman,serif <span>
<span> .......
<p style="margin-bottom:0in; margin-bottom:.0001pt; line-height:normal <span style="font-size:10.0pt; font-family:Times New Roman,serif <span>
}
<p style="margin-bottom:0in; margin-bottom:.0001pt; line-height:normal <span style="font-size:10.0pt; font-family:Times New Roman,serif
<p style="margin-bottom:0in; margin-bottom:.0001pt; line-height:normal <span style="font-size:10.0pt; font-family:Times New Roman,serif public byte[] ImageToByteArray(Image img)
<p style="margin-bottom:0in; margin-bottom:.0001pt; line-height:normal <span style="font-size:10.0pt; font-family:Times New Roman,serif <span>
{
<p style="margin-bottom:0in; margin-bottom:.0001pt; line-height:normal <span style="font-size:10.0pt; font-family:Times New Roman,serif <span>
System.IO.MemoryStream ms = new System.IO.MemoryStream();
<p style="margin-bottom:0in; margin-bottom:.0001pt; line-height:normal <span style="font-size:10.0pt; font-family:Times New Roman,serif <span>
img.Save(ms, System.Drawing.Imaging.ImageFormat.Jpeg);
<p style="margin-bottom:0in; margin-bottom:.0001pt; line-height:normal <span style="font-size:10.0pt; font-family:Times New Roman,serif <span>
return ms.ToArray();
<p style="margin-bottom:0in; margin-bottom:.0001pt; line-height:normal <span style="font-size:10.0pt; font-family:Times New Roman,serif <span>
<span> }<span>
<p style="margin-bottom:0in; margin-bottom:.0001pt; line-height:normal <span style="font-size:10.0pt; font-family:Times New Roman,serif
<p style="margin-bottom:0in; margin-bottom:.0001pt; line-height:normal <span style="font-size:10.0pt; font-family:Times New Roman,serif Display()
<p style="margin-bottom:0in; margin-bottom:.0001pt; line-height:normal <span style="font-size:10.0pt; font-family:Times New Roman,serif <span>
{
<p style="margin-bottom:0in; margin-bottom:.0001pt; line-height:normal <span style="font-size:10.0pt; font-family:Times New Roman,serif <span>
.......
<p style="margin-bottom:0in; margin-bottom:.0001pt; line-height:normal <span style="font-size:10.0pt; font-family:Times New Roman,serif <span>
.......
<p style="margin-bottom:0in; margin-bottom:.0001pt; line-height:normal <span style="font-size:10.0pt; font-family:Times New Roman,serif <span>
Byte[] bytePicData = (Byte[])dt.Rows[0]["PICTURE"];<span> <span><span style="font-family:Times New Roman,serif );<span style="font-size:10.0pt; font-family:Times New Roman,serif <span>

<p style="margin-bottom:0in; margin-bottom:.0001pt; line-height:normal <span style="font-size:10.0pt; font-family:Times New Roman,serif <span>
MemoryStream stmPicData = new MemoryStream(bytePicData);
<p style="margin-bottom:0in; margin-bottom:.0001pt; line-height:normal <span style="font-size:10.0pt; font-family:Times New Roman,serif <span>
PicBox.Image = Bitmap.FromStream(stmPicData);}
<p style="margin-bottom:0in; margin-bottom:.0001pt; line-height:normal <span style="font-size:10.0pt; font-family:Times New Roman,serif <span>
.......
<p style="margin-bottom:0in; margin-bottom:.0001pt; line-height:normal <span style="font-size:10.0pt; font-family:Times New Roman,serif <span>
.......
<p style="margin-bottom:0in; margin-bottom:.0001pt; line-height:normal <span style="font-size:10.0pt; font-family:Times New Roman,serif <span>
}
<span style="font-family:Times New Roman,serif
<br/>

View the full article
 
Back
Top