locked
A Generic Error Occur in GDI+ RRS feed

  • Question

  • Hello Everyone..... I Have an Employee Application, made using C# 2005. Now, before I Upgraded to Win Vista Business SP1, My application works fine... here is the scenario. First if the User Creates or Edits Employee Record, of course it has a picture, after filling the needed information the user will have to browse where the picture is located in his/her machine or shared resource, then once browsed and the Image or Picture is displayed in the Picture Box or Picture Control... He/she will then click the SAVE button, and then.... it's magic... it's saved in the database (SQL SERVER 2005). ------------------------------------------------------------------------------------------------
    SAVING Scenario:
    1) Get the PictureBox's Image/Picture and convert it to Byte[]
    2) Then Save it to the Database (SQL SERVER 2005)

    CODE:

    Byte[] byteResult = Image2ByteArray(PictureBox1.Image);

    public byte[] Image2ByteArray(Image ImageIN)
    {
         using (MemoryStream ms = new MemoryStream())
         {
                ImageIN.Save(ms, System.Drawing.Imaging.ImageFormat.Jpeg); return ms.ToArray();
          }
    }

    SaveRecord();
    --------------------------------------------------------------

    Now here is the thing, in Windows XP (whatever version) its works fine...
    But in Windows Vista..... Ooopsss.. "ERROR".

    public byte[] Image2ByteArray(Image ImageIN)
    {
            using (MemoryStream ms = new MemoryStream())
            {
                  //Error Code Goes and Starts Here
                  //It Says: "A Generic Error Occur in GDI+"
                  //Error Number is: -2147467259

                
                  ImageIN.Save(ms, System.Drawing.Imaging.ImageFormat.Jpeg);
                  return ms.ToArray();
             }
    }

     ----------------------------------------------------------------------------------
    And I'm Thinking to recreate the program using C# 2008, but i doubt that this error will occur regardless of C# version.

    Please Help on this problem.
    What is the best solution for Converting Image to Byte[]?

    A Generic Error Occur in GDI+? What????

    I thought if I build an application perfectly dependent or using .NET Framework it will work fine on Windows XP and Windows VISTA or probably Windows 7 as long as it have the framework installed.


    Please Help.


    More Power Microsoft MSDN.... I've Learned A Lot..
    Thanks and GOD Bless..
    • Edited by Se7en6ix Sunday, May 3, 2009 12:50 PM Edit
    Sunday, May 3, 2009 12:42 PM

Answers

  • Oh Im Sorry for the Late Reply.........


    Because my application is in a rush I needed to use 3rd Party Controls (I Won't Mention Creator of those good third Party Controls) which fixed my problems very well....

    But then Again I Believe that the error is raised because of the way the code converts Image to stream.

    public byte[] Image2ByteArray(Image ImageIN)
    {
            using (MemoryStream ms = new MemoryStream())
            {
                  //Error Code Goes and Starts Here
                  //It Says: "A Generic Error Occur in GDI+"
                  //Error Number is: -2147467259

                
                  ImageIN.Save(ms, System.Drawing.Imaging.ImageFormat.Jpeg);
                  return ms.ToArray();
             }
    }

    Thanks


    • Marked as answer by Se7en6ix Tuesday, May 26, 2009 3:41 PM
    Tuesday, May 26, 2009 3:40 PM

All replies

  • The error message isn't very descriptive.  You probably have a permission problem.  Your posted code runs without error on my Vista and XP systems.
    Sunday, May 3, 2009 3:53 PM
  • Try to run your program on Vista as administrator
    kaymaf
    I hope this helps, if that is what you want, just mark it as answer so that we can move on
    Sunday, May 3, 2009 4:37 PM
  • Hi thanks for the reply......

       

        My User account is SET as Administrator (DOMAIN\MyUsername).. i think i wont have a problem if the permission is the case..

        Here is the Scene:

        I have users of Over 30, 5 of those users will use this program (Employee App.).
       
        Those users has a limited permission account type.... Does it mean that i have to tell my users to run it as Administrator? I hope not.
        it would cause huge problem for a first time Admin like me.. if my users know the admin passwords...


        Yes the code works....... but as admin......

        

        Here my new question.......

        Because it deals with MemoryStream() and memory itself.......

        How can i lift up that security using C#/VB Code........?

        A Code for XP and A Code for Vista?  lol im sorry for the newbie question lol!

        Is it Under System.Security.Permissions Namespace?



    Thanks again for the replies.....


         
       
        



    Sunday, May 3, 2009 5:05 PM
  • -2147467259=0x80004005=E_FAIL
    too general to tell
    Run process monitor to see if there is any file/registry related error.


    MSMVP VC++
    Sunday, May 3, 2009 8:35 PM
  • Can't Find error using Process Monitor

    Here Some Addtional Info......


    When i Browse For A Picture File and then it loads on the Picture Box, I Then Click SAVE...

    Byte[] bImage = Image2ByteArray(PictureBox.Image);

    public byte[] Image2ByteArray(Image ImageIN)
    {
            using (MemoryStream ms = new MemoryStream())
            {             
                  ImageIN.Save(ms, System.Drawing.Imaging.ImageFormat.Jpeg);
                  return ms.ToArray();
             }
    }

    It is then Save in the Database(SQL 2005)...

    This Works fine in XP and Vista...


    Then... I Run the Application Again..... Then I try to Edit the information I Just saved Recently......


    I Will Click the Edit Button...

    Load the Information including the Picture... (note thet the picture being loaded is saved in the SQLSERVER Database)

    here is the code for reading Images from Database....

     public Image ByteArrayToImage(byte[] ByteArrayIn)
     {
                using (MemoryStream ms = new MemoryStream(ByteArrayIn))
                {
                    Image returnImage = Image.FromStream(ms);
                    return returnImage;
                }
      }




    The CASE:

    If I want to change the picture, of course i will browse again and load it in the PictureBox.... and then Click SAVE..

    It works fine AGAIN.........


    BUT.....

    IF I don't want to change or edit the image, and leave it as it is...... If i Click the SAVE button this error appears again..


    public byte[] Image2ByteArray(Image ImageIN)
    {
            using (MemoryStream ms = new MemoryStream())
            {
                  //Error Code Goes and Starts Here
                  //It Says: "A Generic Error Occur in GDI+"
                  //Error Number is: -2147467259

                
                  ImageIN.Save(ms, System.Drawing.Imaging.ImageFormat.Jpeg);
                  return ms.ToArray();
             }
    }


    Well I'm sorry for little information i gave..... and sorry for my Bad English lol


    I guess the Error Starts from Here:

    public Image ByteArrayToImage(byte[] ByteArrayIn)
     {
                using (MemoryStream ms = new MemoryStream(ByteArrayIn))
                {
                    Image returnImage = Image.FromStream(ms);
                    return returnImage;
                }
      }




    Thanks again for the replies.....




    • Edited by Se7en6ix Monday, May 4, 2009 6:21 AM edit
    Monday, May 4, 2009 6:17 AM
  • Could you please post the stack trace right here, usually when an exception is thrown, you could always distill into it and find its stack trace?

    Thanks
    Another Paradigm Shift
    http://shevaspace.blogspot.com
    Tuesday, May 5, 2009 5:30 AM
  • if you dont want to follow up this thread, then close it
    kaymaf
    I hope this helps, if that is what you want, just mark it as answer so that we can move on
    Friday, May 22, 2009 9:53 AM
  • if you dont want to follow up this thread, then close it
    kaymaf
    I hope this helps, if that is what you want, just mark it as answer so that we can move on

    kaymaf
    I hope this helps, if that is what you want, just mark it as answer so that we can move on
    Monday, May 25, 2009 11:36 PM
  • Oh Im Sorry for the Late Reply.........


    Because my application is in a rush I needed to use 3rd Party Controls (I Won't Mention Creator of those good third Party Controls) which fixed my problems very well....

    But then Again I Believe that the error is raised because of the way the code converts Image to stream.

    public byte[] Image2ByteArray(Image ImageIN)
    {
            using (MemoryStream ms = new MemoryStream())
            {
                  //Error Code Goes and Starts Here
                  //It Says: "A Generic Error Occur in GDI+"
                  //Error Number is: -2147467259

                
                  ImageIN.Save(ms, System.Drawing.Imaging.ImageFormat.Jpeg);
                  return ms.ToArray();
             }
    }

    Thanks


    • Marked as answer by Se7en6ix Tuesday, May 26, 2009 3:41 PM
    Tuesday, May 26, 2009 3:40 PM
  • Oh Im Sorry for the Late Reply.........


    Because my application is in a rush I needed to use 3rd Party Controls (I Won't Mention Creator of those good third Party Controls) which fixed my problems very well....

    But then Again I Believe that the error is raised because of the way the code converts Image to stream.

    public byte[] Image2ByteArray(Image ImageIN)
    {
            using (MemoryStream ms = new MemoryStream())
            {
                  //Error Code Goes and Starts Here
                  //It Says: "A Generic Error Occur in GDI+"
                  //Error Number is: -2147467259

                
                  ImageIN.Save(ms, System.Drawing.Imaging.ImageFormat.Jpeg);
                  return ms.ToArray();
             }
    }

    Thanks



        who cares about your third-party creator, stick with the creator that fixed your problem well. From now, dont bother to ask question in this forum because we are not a third party creator.

    kaymaf
    I hope this helps, if that is what you want, just mark it as answer so that we can move on
    Friday, May 29, 2009 8:00 PM
  • Woaaaa! be cool man!!!, Im sorry if i Offended you.... but isn't this too rude?
    "From now, don't bother to ask question in this forum because we are not a third party creator."


    All I'm Saying is "I Believe that the error is raised because of the way the code converts Image to stream."


    ImageIN.Save(ms, System.Drawing.Imaging.ImageFormat.Jpeg);


    I DID NOT MEAN to offend you, or the people who are answering questions (Thanks to them)....


    Oh By the way Mr. Kaymaf "Sir" if you don't feel like answering my questions its okay.....  well thanks again.....


    God Bless












    Sunday, May 31, 2009 9:38 AM