1.first add to button this button name is browse and
add to picture box this name is pcimg
2.now brwose the image and load to image in picture box...coding is
OpenFileDialog open = new OpenFileDialog();
open.Filter = "Image Files(*.jpg; *.jpeg; *.gif; *.bmp)|*.jpg; *.jpeg; *.gif; *.bmp";
if (open.ShowDialog() == DialogResult.OK)
{
Image img = new Bitmap(open.FileName);
pcimg.Image = img.GetThumbnailImage(340, 165, null, new IntPtr());
open.RestoreDirectory = true;
Image thumbimage = pcimg.Image;
pcimg.Image = thumbimage.GetThumbnailImage(100, 100, null, new IntPtr());
}
3.now image convert to the byte.we can using filestream or MemoryStream..memory stream is better than filestream .......coding is
byte[] emp_photo;
MemoryStream ms = new MemoryStream();
pcimg.Image.Save(ms, ImageFormat.Jpeg);
emp_photo = new byte[ms.Length];
ms.Position = 0;
ms.Read(emp_photo, 0, emp_photo.Length);
4.now add image to sql data base....image sql datatype is image
coding is
cmd.Parameters.Add(pm);
cmd.ExecuteNonQuery();
add to picture box this name is pcimg
2.now brwose the image and load to image in picture box...coding is
OpenFileDialog open = new OpenFileDialog();
open.Filter = "Image Files(*.jpg; *.jpeg; *.gif; *.bmp)|*.jpg; *.jpeg; *.gif; *.bmp";
if (open.ShowDialog() == DialogResult.OK)
{
Image img = new Bitmap(open.FileName);
pcimg.Image = img.GetThumbnailImage(340, 165, null, new IntPtr());
open.RestoreDirectory = true;
Image thumbimage = pcimg.Image;
pcimg.Image = thumbimage.GetThumbnailImage(100, 100, null, new IntPtr());
}
3.now image convert to the byte.we can using filestream or MemoryStream..memory stream is better than filestream .......coding is
byte[] emp_photo;
MemoryStream ms = new MemoryStream();
pcimg.Image.Save(ms, ImageFormat.Jpeg);
emp_photo = new byte[ms.Length];
ms.Position = 0;
ms.Read(emp_photo, 0, emp_photo.Length);
4.now add image to sql data base....image sql datatype is image
coding is
SqlParameter pm = new SqlParameter("@logo", SqlDbType.Image);
pm.Value = emp_photo;cmd.Parameters.Add(pm);
cmd.ExecuteNonQuery();
0 comments:
Post a Comment