A generic error occurred in GDI+.

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • pankajprakash
    New Member
    • Feb 2007
    • 70

    A generic error occurred in GDI+.

    Hi all,
    i want to show a image. for this i am using following code.

    private void Display(string sFile)
    {
    try
    {

    Int16 iWidth = 0;
    Int16 iHeight = 0;
    System.Drawing. Image obBMP = new System.Drawing. Bitmap(sFile);
    FileInfo obFileInfo = new FileInfo(sFile) ;

    iWidth = Convert.ToInt16 (obBMP.Width);
    iHeight = Convert.ToInt16 (obBMP.Height);
    if (obBMP.Width > 100)
    {
    iWidth = 100;
    iHeight = Convert.ToInt16 ((obBMP.Height * iWidth) / (obBMP.Width));
    }
    if (iHeight > 110)
    {
    iHeight = 110;
    iWidth = Convert.ToInt16 ((obBMP.Width * iHeight) / (obBMP.Height)) ;
    }


    System.Drawing. Bitmap obBimMap = new System.Drawing. Bitmap(obBMP, iWidth, iHeight);
    System.Drawing. Graphics oDraw = System.Drawing. Graphics.FromIm age(obBimMap);

    Stream output = Response.Output Stream;
    obBimMap.Save(o utput, System.Drawing. Imaging.ImageFo rmat.Bmp);
    obFileInfo = null;
    obBimMap.Dispos e();
    obBimMap = null;
    obBMP.Dispose() ;
    obBMP = null;
    }
    catch (Exception)
    {
    throw;
    }

    }

    This code is working fine for another of my project. But when i run this code in current project it occurs the error "A generic error occurred in GDI+."

    I have also set all the permission of my project folder. But didn't get the reason of this problem.
  • pankajprakash
    New Member
    • Feb 2007
    • 70

    #2
    actually error is occours when we try to save the image in the following line

    obBimMap.Save(o utput, System.Drawing. Imaging.ImageFo rmat.Bmp);

    i have also set the readonly property false of my image folder.


    Originally posted by pankajprakash
    Hi all,
    i want to show a image. for this i am using following code.

    private void Display(string sFile)
    {
    try
    {

    Int16 iWidth = 0;
    Int16 iHeight = 0;
    System.Drawing. Image obBMP = new System.Drawing. Bitmap(sFile);
    FileInfo obFileInfo = new FileInfo(sFile) ;

    iWidth = Convert.ToInt16 (obBMP.Width);
    iHeight = Convert.ToInt16 (obBMP.Height);
    if (obBMP.Width > 100)
    {
    iWidth = 100;
    iHeight = Convert.ToInt16 ((obBMP.Height * iWidth) / (obBMP.Width));
    }
    if (iHeight > 110)
    {
    iHeight = 110;
    iWidth = Convert.ToInt16 ((obBMP.Width * iHeight) / (obBMP.Height)) ;
    }


    System.Drawing. Bitmap obBimMap = new System.Drawing. Bitmap(obBMP, iWidth, iHeight);
    System.Drawing. Graphics oDraw = System.Drawing. Graphics.FromIm age(obBimMap);

    Stream output = Response.Output Stream;
    obBimMap.Save(o utput, System.Drawing. Imaging.ImageFo rmat.Bmp);
    obFileInfo = null;
    obBimMap.Dispos e();
    obBimMap = null;
    obBMP.Dispose() ;
    obBMP = null;
    }
    catch (Exception)
    {
    throw;
    }

    }

    This code is working fine for another of my project. But when i run this code in current project it occurs the error "A generic error occurred in GDI+."

    I have also set all the permission of my project folder. But didn't get the reason of this problem.

    Comment

    • pankajprakash
      New Member
      • Feb 2007
      • 70

      #3
      I got the problem. Actually it is working fine with the gif type image but not working with the bmp and png type image files. But i have to use png.


      Originally posted by pankajprakash
      actually error is occours when we try to save the image in the following line

      obBimMap.Save(o utput, System.Drawing. Imaging.ImageFo rmat.Bmp);

      i have also set the readonly property false of my image folder.

      Comment

      Working...