Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. .NET (Core and Framework)
  4. Message="A generic error occurred in GDI+." Source="System.Drawing" ErrorCode=-2147467259

Message="A generic error occurred in GDI+." Source="System.Drawing" ErrorCode=-2147467259

Scheduled Pinned Locked Moved .NET (Core and Framework)
graphicshelpwinforms
6 Posts 4 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • M Offline
    M Offline
    msrezapro
    wrote on last edited by
    #1

    hi.please note to my code and help me.source image format is jpeg. below is my code.thanks.

    private void Saveimg(Image image)
    {
    MemoryStream stream = new MemoryStream();
    image.Save(stream,System.Drawing.Imaging.ImageFormat.Jpeg);//throw exeption

    byte[]imgdata= new byte[stream.Length];
    imgdata= stream.ToArray();
    string Filename = "c:\\" + Convert.ToString(DateTime.Now.ToFileTime()) +".jpg";

    FileStream fs = new FileStream(Filename, FileMode.CreateNew, FileAccess.Write);
    fs.Write(imgdata, 0, imgdata.Length);
    fs.Close();

    }

    L 1 Reply Last reply
    0
    • M msrezapro

      hi.please note to my code and help me.source image format is jpeg. below is my code.thanks.

      private void Saveimg(Image image)
      {
      MemoryStream stream = new MemoryStream();
      image.Save(stream,System.Drawing.Imaging.ImageFormat.Jpeg);//throw exeption

      byte[]imgdata= new byte[stream.Length];
      imgdata= stream.ToArray();
      string Filename = "c:\\" + Convert.ToString(DateTime.Now.ToFileTime()) +".jpg";

      FileStream fs = new FileStream(Filename, FileMode.CreateNew, FileAccess.Write);
      fs.Write(imgdata, 0, imgdata.Length);
      fs.Close();

      }

      L Offline
      L Offline
      Lost User
      wrote on last edited by
      #2

      This might be ExternalException ,which means that you are trying to save the image using invalid format.Try to replace in your code System.Drawing.Imaging.ImageFormat.Jpeg with image.RowFormat.Notice that .jpg or .jpeg extensions could not guarantee that the format is Jpeg. :)

      Life is a stage and we are all actors!

      modified on Tuesday, August 18, 2009 5:11 AM

      M 1 Reply Last reply
      0
      • L Lost User

        This might be ExternalException ,which means that you are trying to save the image using invalid format.Try to replace in your code System.Drawing.Imaging.ImageFormat.Jpeg with image.RowFormat.Notice that .jpg or .jpeg extensions could not guarantee that the format is Jpeg. :)

        Life is a stage and we are all actors!

        modified on Tuesday, August 18, 2009 5:11 AM

        M Offline
        M Offline
        msrezapro
        wrote on last edited by
        #3

        hi.tanks for answering. but this again throw exeption.please help me.

        L 1 Reply Last reply
        0
        • M msrezapro

          hi.tanks for answering. but this again throw exeption.please help me.

          L Offline
          L Offline
          Lost User
          wrote on last edited by
          #4

          The which kind of exception and where exactly it occurred? Make sure that Image.RowFormat is not equal to Emf, Exif, Icon, MemoryBmp Wmf,which might be not supported by the Image.Save(Stream,ImageFormat) method used into your code. :)

          Life is a stage and we are all actors!

          modified on Tuesday, August 18, 2009 7:56 AM

          D 1 Reply Last reply
          0
          • L Lost User

            The which kind of exception and where exactly it occurred? Make sure that Image.RowFormat is not equal to Emf, Exif, Icon, MemoryBmp Wmf,which might be not supported by the Image.Save(Stream,ImageFormat) method used into your code. :)

            Life is a stage and we are all actors!

            modified on Tuesday, August 18, 2009 7:56 AM

            D Offline
            D Offline
            Dave Lessard
            wrote on last edited by
            #5

            I have a similiar situation when saving an image, no matter what type. It's a local winform client application. When I'm logged onto the machine (I am admistrator) it works fine. When other users without admin rights are logged on, the generic GDI+ error occurs while saving the image. Any ideas on how to get around this? Using Image.Save taking a .png, .jpeg, or .bmp file types, seems to make no difference.

            R 1 Reply Last reply
            0
            • D Dave Lessard

              I have a similiar situation when saving an image, no matter what type. It's a local winform client application. When I'm logged onto the machine (I am admistrator) it works fine. When other users without admin rights are logged on, the generic GDI+ error occurs while saving the image. Any ideas on how to get around this? Using Image.Save taking a .png, .jpeg, or .bmp file types, seems to make no difference.

              R Offline
              R Offline
              RobbKirk
              wrote on last edited by
              #6

              Same shit. Save method creates file, but doesn't write. And the very strange is GDI+ error. As soon as I know it doesn't return any error besides cases when the pointer to Image raw data is not returned. In fact, GDI+ deals with windows context (Device Context) of the control where image is shown. Therefore, it might be GDI+ API can't get the control's handle or doesn't has an access right to the control.. maybe .NET blocks the access to its controls from outside dll request. From other side all components are in the same thread, though maybe this Save operation opens new thread???? Any idea?

              1 Reply Last reply
              0
              Reply
              • Reply as topic
              Log in to reply
              • Oldest to Newest
              • Newest to Oldest
              • Most Votes


              • Login

              • Don't have an account? Register

              • Login or register to search.
              • First post
                Last post
              0
              • Categories
              • Recent
              • Tags
              • Popular
              • World
              • Users
              • Groups