I save panel as an image in database by using this code:
public Form2()
{
InitializeComponent();
}
public static byte[] ImageToByte2(Bitmap img)
{
byte[] byteArray = new byte[0];
using (MemoryStream stream = new MemoryStream())
{
img.Save(stream, System.Drawing.Imaging.ImageFormat.Png);
stream.Close();
byteArray = stream.ToArray();
}
return byteArray;
}
private void button1_Click(object sender, EventArgs e)
{
Form1 fom = new Form1();
Bitmap bitmap = new Bitmap(fom.panel1.ClientSize.Width,
fom.panel1.ClientSize.Height);
fom.panel1.DrawToBitmap(bitmap, fom.panel1.ClientRectangle);
byte[] imgArray = ImageToByte2(bitmap);
ImageData img = new ImageData
{
ClassName = textBox1.Text,
Password = textBox2.Text,
Image = imgArray,
};
using (BoardDatabaseEntities dc = new BoardDatabaseEntities())
{
dc.ImageDatas.Add(img);
dc.SaveChanges();
MessageBox.Show("Saved into database");
}
this.Close();
}
I am trying display images from database on webpage (view control) but no success yet. There are many source codes on internet but they all upload a file. Codes are for UploadedFile
. I just can't figure out how to make it (those codes) suitable for my situation. Could you please help?