CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 11 of 11
  1. #1
    Join Date
    May 2014
    Posts
    6

    Exclamation PictureBox Generic Error GDI+ Error Problem ! HELP PLEASE

    I am doing a project.With a button from PictureBox I want to take the help of webcam photographs, and want to save it to my computer.
    This My codes;

    Button1_Click(){

    pictureBox1.Image.Save(string.Format(Application.S tartupPath+"\\Resimler\\kayit{0}.png",a,System.Dra wing.Imaging.ImageFormat.Png));

    }

    But it's not working. I'm constantly getting the error. Error: "Generic Error GDI+" , How can i solve this problem. Please Help, this my School project

    Sorry for bad english

  2. #2
    Join Date
    Jan 2006
    Location
    Fox Lake, IL
    Posts
    15,007

    Re: PictureBox Generic Error GDI+ Error Problem ! HELP PLEASE

    Compute the value FIRST using a String variable. Make sure that it is correct, and then use it in the .Save event
    David

    CodeGuru Article: Bound Controls are Evil-VB6
    2013 Samples: MS CODE Samples

    CodeGuru Reviewer
    2006 Dell CSP
    2006, 2007 & 2008 MVP Visual Basic
    If your question has been answered satisfactorily, and it has been helpful, then, please, Rate this Post!

  3. #3
    Join Date
    May 2014
    Posts
    6

    Re: PictureBox Generic Error GDI+ Error Problem ! HELP PLEASE

    Firs of all , thanks for reply. I do not know too much C# , How would you do? For example, can you write? please

  4. #4
    Arjay's Avatar
    Arjay is offline Moderator / EX MS MVP Power Poster
    Join Date
    Aug 2004
    Posts
    13,490

    Re: PictureBox Generic Error GDI+ Error Problem ! HELP PLEASE

    Quote Originally Posted by hknzq View Post
    Firs of all , thanks for reply. I do not know too much C# , How would you do? For example, can you write? please
    Code:
    button1_Click()
    {
      var filePath = String.Format(Application.StartupPath + "\\Resimler\\kayit{0}.png", a); // <-- what is 'a' in your code?
      pictureBox1.Image.Save(filePath, System.Drawing.Imaging.ImageFormat.Png);
     }
    Break out the file path as I've shown above. In your original code, you had the closing ')' for the String.Format call in the wrong place.

    You also need to track down what 'a' is.

  5. #5
    Join Date
    May 2014
    Posts
    6

    Re: PictureBox Generic Error GDI+ Error Problem ! HELP PLEASE

    Quote Originally Posted by Arjay View Post
    Code:
    button1_Click()
    {
      var filePath = String.Format(Application.StartupPath + "\\Resimler\\kayit{0}.png", a); // <-- what is 'a' in your code?
      pictureBox1.Image.Save(filePath, System.Drawing.Imaging.ImageFormat.Png);
     }
    Break out the file path as I've shown above. In your original code, you had the closing ')' for the String.Format call in the wrong place.

    You also need to track down what 'a' is.
    First of all, thanks for reply.

    This my save button click() code;

    if (txtAd.Text != "" && txtSoyad.Text != "" && txtTC.Text != "" && txtNo.Text != "" && txtBaba.Text != "" && txtBolum.Text != "" && txtGun.Text != "" && txtAy.Text != "" && txtYil.Text != "" && txtAdres.Text != "" && txtTel.Text != "")
    {
    button4.Enabled = true;
    var filePath = String.Format(Application.StartupPath + "\\Resimler\\kayit{0}.png", a);
    pictureBox1.Image.Save(filePath, System.Drawing.Imaging.ImageFormat.Png);


    if (a == 2)
    {
    MessageBox.Show("En Fazla 2 Kare Çekebilirsiniz. Çıkıştuşuna basarak Kayıtların silip, yeniden oluşturabilirsiniz.", "UYARI!", MessageBoxButtons.OKCancel, MessageBoxIcon.Warning);

    button4.Enabled = false;
    }
    label6.Text = (a.ToString()) + " Fotoğraf çekildi";
    a = a + 1;

    }
    else { MessageBox.Show("Lütfen tüm gerekli alanları doldurunuz...", "UYARI!", MessageBoxButtons.OK, MessageBoxIcon.Information); }

    But This error;

    See the end of this message for details on invoking
    just-in-time (JIT) debugging instead of this dialog box.

    ************** Exception Text **************
    System.Runtime.InteropServices.ExternalException (0x80004005): A generic error occurred in GDI+.
    at System.Drawing.Image.Save(String filename, ImageCodecInfo encoder, EncoderParameters encoderParams)
    at System.Drawing.Image.Save(String filename, ImageFormat format)
    at KameradanGoruntuAlmak.Form1.button4_Click(Object sender, EventArgs e)
    at System.Windows.Forms.Control.OnClick(EventArgs e)
    at System.Windows.Forms.Button.OnClick(EventArgs e)
    at System.Windows.Forms.Button.OnMouseUp(MouseEventArgs mevent)
    at System.Windows.Forms.Control.WmMouseUp(Message& m, MouseButtons button, Int32 clicks)
    at System.Windows.Forms.Control.WndProc(Message& m)
    at System.Windows.Forms.ButtonBase.WndProc(Message& m)
    at System.Windows.Forms.Button.WndProc(Message& m)
    at System.Windows.Forms.Control.ControlNativeWindow.OnMessage(Message& m)
    at System.Windows.Forms.Control.ControlNativeWindow.WndProc(Message& m)
    at System.Windows.Forms.NativeWindow.Callback(IntPtr hWnd, Int32 msg, IntPtr wparam, IntPtr lparam)


    ************** Loaded Assemblies **************
    mscorlib
    Assembly Version: 4.0.0.0
    Win32 Version: 4.0.30319.1 (RTMRel.030319-0100)
    CodeBase: file:///C:/Windows/Microsoft.NET/Framework/v4.0.30319/mscorlib.dll
    ----------------------------------------
    KameradanGoruntuAlmak
    Assembly Version: 1.0.0.0
    Win32 Version: 1.0.0.0
    CodeBase: file:///C:/Program%20Files/MK%DC%20%D6grenci%20Kayit%20Otomasyonu/MK%DC%20%D6grenci%20Kayit%20Otomasyonu/KameradanGoruntuAlmak.exe
    ----------------------------------------
    System.Windows.Forms
    Assembly Version: 4.0.0.0
    Win32 Version: 4.0.30319.1 built by: RTMRel
    CodeBase: file:///C:/Windows/Microsoft.Net/assembly/GAC_MSIL/System.Windows.Forms/v4.0_4.0.0.0__b77a5c561934e089/System.Windows.Forms.dll
    ----------------------------------------
    System.Drawing
    Assembly Version: 4.0.0.0
    Win32 Version: 4.0.30319.1 built by: RTMRel
    CodeBase: file:///C:/Windows/Microsoft.Net/assembly/GAC_MSIL/System.Drawing/v4.0_4.0.0.0__b03f5f7f11d50a3a/System.Drawing.dll
    ----------------------------------------
    System
    Assembly Version: 4.0.0.0
    Win32 Version: 4.0.30319.1 built by: RTMRel
    CodeBase: file:///C:/Windows/Microsoft.Net/assembly/GAC_MSIL/System/v4.0_4.0.0.0__b77a5c561934e089/System.dll
    ----------------------------------------
    System.Configuration
    Assembly Version: 4.0.0.0
    Win32 Version: 4.0.30319.1 (RTMRel.030319-0100)
    CodeBase: file:///C:/Windows/Microsoft.Net/assembly/GAC_MSIL/System.Configuration/v4.0_4.0.0.0__b03f5f7f11d50a3a/System.Configuration.dll
    ----------------------------------------
    System.Xml
    Assembly Version: 4.0.0.0
    Win32 Version: 4.0.30319.1 built by: RTMRel
    CodeBase: file:///C:/Windows/Microsoft.Net/assembly/GAC_MSIL/System.Xml/v4.0_4.0.0.0__b77a5c561934e089/System.Xml.dll
    ----------------------------------------
    System.Data
    Assembly Version: 4.0.0.0
    Win32 Version: 4.0.30319.1 (RTMRel.030319-0100)
    CodeBase: file:///C:/Windows/Microsoft.Net/assembly/GAC_32/System.Data/v4.0_4.0.0.0__b77a5c561934e089/System.Data.dll
    ----------------------------------------
    System.Core
    Assembly Version: 4.0.0.0
    Win32 Version: 4.0.30319.1 built by: RTMRel
    CodeBase: file:///C:/Windows/Microsoft.Net/assembly/GAC_MSIL/System.Core/v4.0_4.0.0.0__b77a5c561934e089/System.Core.dll
    ----------------------------------------
    System.Transactions
    Assembly Version: 4.0.0.0
    Win32 Version: 4.0.30319.1 (RTMRel.030319-0100)
    CodeBase: file:///C:/Windows/Microsoft.Net/assembly/GAC_32/System.Transactions/v4.0_4.0.0.0__b77a5c561934e089/System.Transactions.dll
    ----------------------------------------
    System.EnterpriseServices
    Assembly Version: 4.0.0.0
    Win32 Version: 4.0.30319.1 (RTMRel.030319-0100)
    CodeBase: file:///C:/Windows/Microsoft.Net/assembly/GAC_32/System.EnterpriseServices/v4.0_4.0.0.0__b03f5f7f11d50a3a/System.EnterpriseServices.dll
    ----------------------------------------
    System.Numerics
    Assembly Version: 4.0.0.0
    Win32 Version: 4.0.30319.1 built by: RTMRel
    CodeBase: file:///C:/Windows/Microsoft.Net/assembly/GAC_MSIL/System.Numerics/v4.0_4.0.0.0__b77a5c561934e089/System.Numerics.dll
    ----------------------------------------
    WebCam_Capture
    Assembly Version: 1.0.2087.23475
    Win32 Version: 1.0.2087.23475
    CodeBase: file:///C:/Program%20Files/MK%DC%20%D6grenci%20Kayit%20Otomasyonu/MK%DC%20%D6grenci%20Kayit%20Otomasyonu/WebCam_Capture.DLL
    ----------------------------------------

    ************** JIT Debugging **************
    To enable just-in-time (JIT) debugging, the .config file for this
    application or computer (machine.config) must have the
    jitDebugging value set in the system.windows.forms section.
    The application must also be compiled with debugging
    enabled.

    For example:

    <configuration>
    <system.windows.forms jitDebugging="true" />
    </configuration>

    When JIT debugging is enabled, any unhandled exception
    will be sent to the JIT debugger registered on the computer
    rather than be handled by this dialog box.

  6. #6
    Arjay's Avatar
    Arjay is offline Moderator / EX MS MVP Power Poster
    Join Date
    Aug 2004
    Posts
    13,490

    Re: PictureBox Generic Error GDI+ Error Problem ! HELP PLEASE

    Use need to use the debugger to help you figure this out.

    Put a breakpoint on the following line (click on the line and press F9)

    Code:
    pictureBox1.Image.Save(filePath,
    Press F5 to start debugging.

    When the debugger breaks on the breakpoint, hover the mouse over the filePath variable to see its contents.

    Does it look like it's been formed correctly?

  7. #7
    Join Date
    May 2014
    Posts
    6

    Re: PictureBox Generic Error GDI+ Error Problem ! HELP PLEASE

    Quote Originally Posted by Arjay View Post
    Use need to use the debugger to help you figure this out.

    Put a breakpoint on the following line (click on the line and press F9)

    Code:
    pictureBox1.Image.Save(filePath,
    Press F5 to start debugging.

    When the debugger breaks on the breakpoint, hover the mouse over the filePath variable to see its contents.

    Does it look like it's been formed correctly?
    In the project are working normally.
    But after Setup on the computer when I install, I get this error. (

  8. #8
    Arjay's Avatar
    Arjay is offline Moderator / EX MS MVP Power Poster
    Join Date
    Aug 2004
    Posts
    13,490

    Re: PictureBox Generic Error GDI+ Error Problem ! HELP PLEASE

    Quote Originally Posted by hknzq View Post
    In the project are working normally.
    But after Setup on the computer when I install, I get this error. (
    Add some code to verify that the path exists and that you have access to it. If you are trying to save a file to the location where your app has been installed you probably don't have access.

  9. #9
    Join Date
    May 2014
    Posts
    6

    Re: PictureBox Generic Error GDI+ Error Problem ! HELP PLEASE

    Quote Originally Posted by Arjay View Post
    Add some code to verify that the path exists and that you have access to it. If you are trying to save a file to the location where your app has been installed you probably don't have access.
    thanks for reply,,

    But I creating installation "Resimler" folder, I add in the program files. Access road section where the program is installed already, is not it?

  10. #10
    Arjay's Avatar
    Arjay is offline Moderator / EX MS MVP Power Poster
    Join Date
    Aug 2004
    Posts
    13,490

    Re: PictureBox Generic Error GDI+ Error Problem ! HELP PLEASE

    Quote Originally Posted by hknzq View Post
    thanks for reply,,

    But I creating installation "Resimler" folder, I add in the program files. Access road section where the program is installed already, is not it?
    From what I said earlier:
    If you are trying to save a file to the location where your app has been installed you probably don't have access.
    When you install a program, your permissions get elevated.

    When you run the program, the program runs under non-elevated permissions, so if you try to save a file in the same place the app has been installed, you probably won't have the required permissions.

    To test this, run the app with administrator permissions. If you can save the file, it's a permissions issue. If you can't, it's something else.

  11. #11
    Join Date
    May 2014
    Posts
    6

    Re: PictureBox Generic Error GDI+ Error Problem ! HELP PLEASE

    Quote Originally Posted by Arjay View Post
    From what I said earlier:


    When you install a program, your permissions get elevated.

    When you run the program, the program runs under non-elevated permissions, so if you try to save a file in the same place the app has been installed, you probably won't have the required permissions.

    To test this, run the app with administrator permissions. If you can save the file, it's a permissions issue. If you can't, it's something else.
    Thank you for everything Arjay !!

    I solved this problem, Thanks to you. Only a compatibility issue. I'm using Windows 7 , and right-click on the program,"troubleshoot compatibility" option clicked. Windows XP Service Pack 2 compatibility did. And Problem Solved Thankssss

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured