protected void btnCrop_Click(object sender, EventArgs e)
{
string ImageName = Session["pic"].ToString();
int x = Convert.ToInt32(X.Value);
int y = Convert.ToInt32(Y.Value);
int w = Convert.ToInt32(W.Value);
int h = Convert.ToInt32(H.Value);
double ratio = 0;
double w1 = double.Parse(Session["width"].ToString());
ratio = (w1 / 400.0);
double w12 = w * ratio;
double h12 = h * ratio;
double x1 = x * ratio;
double y1 = y * ratio;
int wm = int.Parse(Math.Round(w12).ToString());
int hm = int.Parse(Math.Round(h12).ToString());
int xm = int.Parse(Math.Round(x1).ToString());
int ym = int.Parse(Math.Round(y1).ToString());
double imgratio = w12 / h12;
string pathcrop = "";
byte[] CropImage = Crop(path + Session["pic"].ToString(), w, h, x, y);
using (MemoryStream ms = new MemoryStream(CropImage, 0, CropImage.Length))
{
ms.Write(CropImage, 0, CropImage.Length);
using (SD.Image CroppedImage = SD.Image.FromStream(ms, true))
{
string SaveTo = path1 + Session["pic"].ToString();
CroppedImage.Save(SaveTo, CroppedImage.RawFormat);
pnlCrop.Visible = false;
pnlCropped.Visible = true;
imgCropped.ImageUrl = "Admin/ProductImage/Product/Cropped/" + Session["pic"].ToString();
pathcrop = path1 + Session["pic"].ToString();
}
}
try
{
Size thnmb = new Size();
double height = (168.0 / imgratio);
thnmb.Width = 168;
thnmb.Height = int.Parse(Math.Round(height).ToString());
double hbig = (392.0 / imgratio);
Size big = new Size();
big.Width = 392;
big.Height = int.Parse(Math.Round(hbig).ToString());
Size zoom = new Size();
zoom.Width = 600;
zoom.Height = 600;
string pathbig = "/Admin/ProductImage/Product/Big/" + Session["pic"].ToString();
string paththumb = "/Admin/ProductImage/Product/Thumb/" + Session["pic"].ToString();
string pathzoom = "/Admin/ProductImage/Product/Zoom/" + Session["pic"].ToString();
string path5 = Request.PhysicalApplicationPath + "Admin\\ProductImage\\Product\\Cropped\\" + Session["pic"].ToString();
string path4 = Request.PhysicalApplicationPath;
Common.resizeImage(System.Drawing.Image.FromFile(path5), big).Save(path4 + "Admin\\ProductImage\\Product\\Big\\" + Session["pic"].ToString());
Common.resizeImage(System.Drawing.Image.FromFile(path5), thnmb).Save(path4 + "Admin\\ProductImage\\Product\\Thumb\\" + Session["pic"].ToString());
Common.resizeImage(System.Drawing.Image.FromFile(path5), zoom).Save(path4 + "Admin\\ProductImage\\Product\\Zoom\\" + Session["pic"].ToString());
con.cmdmain.Parameters.AddWithValue("@imgthumb", paththumb);
con.cmdmain.Parameters.AddWithValue("@imgbig", pathbig);
con.cmdmain.Parameters.AddWithValue("@imgzoom", pathzoom);
con.cmdnonquery("update product set pic=@imgthumb,pic_big=@imgbig,pic_zoom=@imgzoom where productid='" + Request["pid"] + "'");
con.cmdmain.Parameters.AddWithValue("@pid", Request["pid"]);
con.cmdnonquery("insert into product_images(pid,pic,picbig,piczoom) values(@pid,@imgthumb,@imgbig,@imgzoom)");
pnlCrop.Visible = false;
pnlCropped.Visible = true;
imgCropped.ImageUrl = "Admin/ProductImage/Product/Cropped/" + Session["pic"].ToString();
Response.Write("<script>alert('Item Cropped Successfully!!')</script>");
Response.Redirect("ProductList.aspx");
}
catch (Exception ex)
{
Response.Write("some technical problem");
}
}
A generic error occurred in GDI+. this error rise during when image cropped and resize this image
...
please help me anybody