private void Mypicbox_click (object sender, EventArgs e)
{
Try
{
OpenFileDialog ofdpic = new OpenFileDialog ();
Ofdpic.filter = "*.jpg,*.jpeg,*.bmp,*.gif,*.ico,*.png,*.tif,*.wmf|*.jpg;*.jpeg;*.bmp;*.gif;*.ico;*.png;*.tif;*. WMF ";
Ofdpic.filterindex = 1;
Ofdpic.filename = "";
if (ofdpic.showdialog () = = DialogResult.OK)
{
String spicpaht = OfdPic.FileName.ToString ();
Bitmap bmpic = new Bitmap (SPICPAHT);
Point ptloction = new Point (bmpic.size);
if (Ptloction.x > Mypicbox. Size.width | | PTLOCTION.Y > Mypicbox. Size.Height)
{
Image fills the image frame, and the image is held in proportion
Mypicbox. SizeMode = Pictureboxsizemode.zoom;
}
Else
{
The image is placed in the image frame
Mypicbox. SizeMode = Pictureboxsizemode.centerimage;
}
Gets the path of the image
Mypicbox. Load (SPICPAHT);
Mypicbox. Image = This.mypicbox.Image;
AutoSave (Mypicbox);
}
}
catch (Exception exp)
{
Throw exp;
}
}
private void AutoSave (PictureBox mypicbox)
{
String Opath = @ "Data\image";
String photoname = DateTime.Now.Ticks.ToString ();
This.imagename = Photoname;
if (Opath.substring (opath.length-1, 1)! = @ "\")
Opath = Opath + @ "\";
String path1 = Opath + DateTime.Now.ToShortDateString ();
if (! Directory.Exists (path1))
{
Directory.CreateDirectory (path1);
}
PictureBox1.Image.Save (path1 + "\" + Photoname + ". jpg", System.Drawing.Imaging.ImageFormat.Jpeg);
Shrinking the image
System.Drawing.Bitmap Objpic, Objnewpic;
Try
{
Mypicbox. Image.Save (path1);
Objpic = new System.Drawing.Bitmap (Mypicbox. Image);
Objnewpic = new System.Drawing.Bitmap (Objpic, Mypicbox. Width, Mypicbox. Height);
Objnewpic=new System.Drawing.Bitmap (objpic,320,240);//Picture saved size size
Objnewpic.save (path1 + "\" + ImageName + ". jpg");
}
catch (Exception exp) {throw exp;}
Finally
{
Objpic = null;
Objnewpic = null;
}
}
private string ImageName {get; set;}
PictureBox upload pictures from local and save in disk directory