Click here to Skip to main content
15,884,177 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
XML
<asp:Panel ID="pnlCrop" runat="server" Visible="false">
      <asp:Image ID="imgCrop" runat="server" />
      <br />
      <asp:HiddenField ID="X" runat="server" />
      <asp:HiddenField ID="Y" runat="server" />
      <asp:HiddenField ID="W" runat="server" />
      <asp:HiddenField ID="H" runat="server" />
      <asp:Button ID="btnCrop" runat="server" Text="Crop" OnClick="btnCrop_Click" />
    </asp:Panel>




protected void btnCrop_Click(object sender, EventArgs e)
{
  string ImageName = Session[&amp;amp;quot;WorkingImage&amp;amp;quot;].ToString();
  int w = Convert.ToInt32(W.Value);
  int h = Convert.ToInt32(H.Value);
  int x = Convert.ToInt32(X.Value);
  int y = Convert.ToInt32(Y.Value);

  byte[] CropImage = Crop(path + ImageName, 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 = path + &amp;amp;quot;crop&amp;amp;quot; + ImageName;
      CroppedImage.Save(SaveTo, CroppedImage.RawFormat);
      pnlCrop.Visible = false;
      pnlCropped.Visible = true;
      imgCropped.ImageUrl = &amp;amp;quot;images/crop&amp;amp;quot; + ImageName;
    }
  }
}
Posted

1 solution

Hey there,

It could be one of these lines:
C#
int w = Convert.ToInt32(W.Value);
  int h = Convert.ToInt32(H.Value);
  int x = Convert.ToInt32(X.Value);
  int y = Convert.ToInt32(Y.Value);


This Exception could occur if any of the hidden fields in these statement have empty value and since you have not set a default Int value in these lines:
ASP.NET
<asp:hiddenfield id="X" runat="server"/>
     <asp:hiddenfield id="Y" runat="server"  />
     <asp:hiddenfield id="W" runat="server" />
     <asp:hiddenfield id="H" runat="server"/>
I susspect that this is causing the Exception.
Anyway, either set a default value like e.g,
ASP.NET
<asp:hiddenfield id="Y" runat="server" value="0"  />

or check the Hidden Fields value is not Empty String before Converting them, e.g,
C#
int h = H.Value != string.empty ? Convert.ToInt32(H.Value) : 0;


Hope it helps
Azee...
 
Share this answer
 
v2
Comments
Member 10170389 4-Oct-13 2:01am    
I set a default value as zero for all hidden fileds ,though its showing the error i.e parameter is not valid

Line 113: catch (Exception Ex)
Line 114: {
Line 115: throw (Ex);
Line 116: }
Line 117: }
How i can handle that error & Iam new to Asp.net programming

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

  Print Answers RSS
Top Experts
Last 24hrsThis month


CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900