1
Reply

Error while converting Physical path into bitmapImage

suresh s

suresh s

Oct 29 2008 8:56 PM
4.8k

I have a task of Embeding Image with text.it works fine in Ordinary Asp.Net Page but Ajax.

I have come accross the error"Parameter is not vaid" while converting Physical path of image into bitmap image.I am sending code(Aspx code and class file) with this mail kindly Let me know how to solve this error.

Code:

 

Aspx Page:

private void WaterImaging()
    {
        if (!string.IsNullOrEmpty(fuPictureImage.PostedFile.FileName))
        {

            if (!string.IsNullOrEmpty(txtEmbedText.Text) & !string.IsNullOrEmpty(txtLeft.Text) & !string.IsNullOrEmpty(txtTop.Text))
            {
               
                string imagePath = null;
                string strFileNameToSave = null;
                string fname = null;

                imagePath = fuPictureImage.PostedFile.FileName;
                fname = Path.GetFileName(imagePath);
                strFileNameToSave = Server.MapPath(".") + @"\uploads\watermarkimages\" + fname;
                DAMS_Cls_Imaging.EmbedText(imagePath, txtEmbedText.Text, ddlFontName.SelectedItem.Text, ddlFontColor.SelectedItem.Text, ddlSize.SelectedItem.Text, txtLeft.Text, txtTop.Text, strFileNameToSave);
               
            }
            else
            {
                ClientScript.RegisterStartupScript(this.GetType(), "Message", "alert('Enter all the Parameter Values for Embed a Text');", true);
            }
        }

        else
        {
            ClientScript.RegisterStartupScript(this.GetType(), "Message", "alert('Select Image to perform the Operation');", true);
        }
           
    }

 

 

 Class.cs(File)

 public static Bitmap EmbedImage(string imagePath, string imgEmbedPath, string width, string height, string left, string top)
         {
             Graphics graphEmbedImage = default(Graphics);
             //Dim BrushColor As System.Drawing.Brush
           
             string strImagePath = null;
             string strTempPath = null;
             strTempPath = Path.GetFileName(imagePath);
             strImagePath = Path.GetFullPath(imagePath);
             Bitmap bmpImage = new Bitmap(strImagePath); \\This is where I am getting Error Parameter not valid"
           
             try {
                 Image embededImage = default(Image);
                 embededImage = Image.FromFile(imgEmbedPath);
               
                 int iWidth = 0;
                 int iHeight = 0;
                 int iLeft = 0;
                 int iTop = 0;
               
                 iWidth = Convert.ToInt32(width);
                 iHeight = Convert.ToInt32(height);
                 iLeft = Convert.ToInt32(left);
                 iTop = Convert.ToInt32(top);
                 graphEmbedImage = Graphics.FromImage(bmpImage);
                 graphEmbedImage.DrawImage(embededImage, iLeft, iTop, iWidth, iHeight);
                 return bmpImage;
             }
             catch (Exception ex) {
                 throw ex;
             }
             finally {
                 graphEmbedImage.Dispose();
             }
           
         }

 

thanks



Answers (1)