I have byte-translated images in the database.And I have tags for these images. The user needs to search the image by entering the desired tags in the Listbox. PictureBox must be created up to the number of pictures.
Fail error message:
An unhandled exception of type 'System.ArgumentException' occurred in System.Drawing.dll
Additional information: Parameter is not valid.
Here are my codes;
PictureBox[] img = new PictureBox[9999];
for (int j = 0; j < listBox1.Items.Count; j++)
{
con.Open();
MySqlCommand cmdImgCount = new MySqlCommand("select count(scan.image) from deu_scanner.scan where scan.id_Image IN (select kw_img.FK_idImg from deu_scanner.kw_img where kw_img.FK_idKeyword IN (select keyword.idkeyword from deu_scanner.keyword where keyword.keywordName='" + listBox1.Items[j] + "'));", con);
imgCount = Convert.ToInt32(cmdImgCount.ExecuteScalar().ToString());
con.Close();
ArrayList ar = new ArrayList();
for (int i = 0; i < imgCount; i++)
{
con.Open();
MySqlCommand cmd = new MySqlCommand("select scan.image from deu_scanner.scan where scan.id_Image IN (select kw_img.FK_idImg from deu_scanner.kw_img where kw_img.FK_idKeyword IN (select keyword.idkeyword from deu_scanner.keyword where keyword.keywordName='" + listBox1.Items[j] + "'))", con);
MySqlDataReader dr = cmd.ExecuteReader();
while (dr.Read())
{
byte[] imagedata = (byte[])dr["image"];
MemoryStream memorystream = new MemoryStream(imagedata, 0, imagedata.Length);
memorystream.Write(imagedata, 0, imagedata.Length);
memorystream.Position = 0;
Image sourceImg = Image.FromStream(memorystream, true);
clonedImg = new Bitmap(sourceImg.Width, sourceImg.Height);
var copy = Graphics.FromImage(clonedImg);
copy.DrawImage(sourceImg, 0, 0);
ar.Add(clonedImg);
}
con.Close();
}
for (int k = 0; k < imgCount; k++)
{
img[k] = new PictureBox();
img[k].Name = "image-" + k.ToString();
img[k].Image = (Image)ar[k];
img[k].Visible = true;
img[k].SizeMode = PictureBoxSizeMode.StretchImage;
img[k].SetBounds(12 + k * 150, 180, 120, 120);
this.Controls.Add(img[k]);
img[k].BringToFront();
}
}
Update (from comments): The database is filled with this code
SaveFileDialog save = new SaveFileDialog();
save.Filter = "JPEG(.JPG)|.jpg";
FileStream fs = new FileStream(save.FileName, FileMode.Open, FileAccess.Read);
BinaryReader br = new BinaryReader(fs);
byte[] data = br.ReadBytes(Convert.ToInt32(fs.Length));
br.Close();
fs.Close();