Hi..
I am working on byte to bitmap image conversion.. so first of all i stored picture in bytes and then stored it in database.. but when I get back picture and fetch it in pictureBox than following exception is occuring ..
System.ArgumentException was unhandled
Message="Parameter is not valid."
while i have code..
adpt = new SqlDataAdapter("select Picture_pic from Purchase_Material",conn);
dt = new DataTable();
adpt.Fill(dt);
if (dt.Rows.Count > 0)
{
foreach(DataRow row in dt.Rows)
{
this.buff = (byte[])row[0];
}
MemoryStream stream = new MemoryStream(this.buff, true);
if (stream.Length == 0L)
{
this.PIC_Lable.Visible = true;
}
else
{
stream.Write(this.buff, 0, this.buff.Length);
//Bitmap bitmap = new Bitmap((System.IO.Stream)stream);
//System.Drawing.Bitmap..ctor(String filename)
System.Drawing.Bitmap.
this.pictureBox1.Image = bitmap;
}
}
please help me...
Loading
Suthish NairPosted Jun 28, 2011, 1:38 AM
Kanhialal kkPosted Jun 28, 2011, 12:17 AM
sir there is only single row in database while i am getting converted picture in query analyzer I mean that column is not empty in database..
also I am placing picture in PictureBox than converting into byte after that going to store in database...
VulpesPosted Jun 27, 2011, 8:46 AM
Suthish NairPosted Jun 27, 2011, 8:22 AM
Kanhialal kkPosted Jun 27, 2011, 6:37 AM
in database a table contains a column with name of
(picture having datatype image)
while below is the code which is used to get image...
private void button1_Browse_Click(object sender, EventArgs e)
{
if (this.openFileDialog1.ShowDialog() == DialogResult.OK)
{
this.PIC_Lable.Visible = false;
this.pictureBox1.Image = Image.FromFile(this.openFileDialog1.FileName);
try
{
this.file = this.openFileDialog1.FileName;
FileStream stream = new FileStream(this.file, (FileMode)FileMode.Open, (FileAccess)FileAccess.Read);
this.buff = new byte[stream.Length];
stream.Read(this.buff, 0, (int)stream.Length);
stream.Close();
}
catch (ArgumentException exception)
{
MessageBox.Show(exception.Message, "Error!");
}
}
}
this is the code..
VulpesPosted Jun 27, 2011, 6:02 AM
How did you save the image to the database in the first place and what type of image is it?
Kanhialal kkPosted Jun 27, 2011, 5:51 AM
VulpesPosted Jun 27, 2011, 5:43 AM
Kanhialal kkPosted Jun 27, 2011, 5:28 AM
still same error..
VulpesPosted Jun 25, 2011, 8:49 AM