Bitmap(string) constructor throws ArgumentException

Answered Bitmap(string) constructor throws ArgumentException

  • Wednesday, May 10, 2006 3:40 PM
     
     

    Hi

    I'm trying to create a bitmap on the fly from an on disk image resource (PNGs in this case).  I can create one fine, but when i try to create the next one the Bitmap constructor throws an ArgumentException with the message "Parameter is not valid".  The weird thing is that the second image (Pan2.png) is an exact duplicate of the first image (ZoomExtent.png) which creates successfully so there is no difference between the dimensions, color depth, format, etc of the two images.  Here's the suspect code below:

    this.tsbFullExtent.DisplayStyle = System.Windows.Forms.ToolStripItemDisplayStyle.Image;

    this.tsbFullExtent.Image = new Bitmap(@".\Resources\ZoomExtent.png"); // Creates successfully

    this.tsbPan.DisplayStyle = System.Windows.Forms.ToolStripItemDisplayStyle.Image;

    this.tsbPan.Image = new Bitmap(@".\Resources\Pan2.png"); // Throws ArgumentException

    Has anyone ever seen this before or have any insight at all?  Any help would be greatly appreciated.

    Thanks,

    Jeremy

All Replies

  • Wednesday, May 10, 2006 5:08 PM
    Moderator
     
     

    try



    Bitmap bmp = new Bitmap(@".\Resources\Pan2.png");
    this.tsbPan.Image = bmp;

     
    And let us know which line is raising the exception.

  • Wednesday, May 10, 2006 6:17 PM
     
     

    It's the first line:

    Bitmap bmp = new Bitmap(@".\Resources\Pan2.png");  // Throws ArgumentException

  • Thursday, May 11, 2006 5:24 PM
    Moderator
     
     Answered

    That means either .\Resources\pan2.png does not exist, or the PNG file has a single dimension greater than 65,535 pixels (I'm assuming that means it's wider or taller than 65,535 pixels).  In other words, an unsupported format.

    Try Path.GetFullPath(@".\Resources\pan2.png") to get the full path when debugging.  e.g.:


    Bitmap bmp = new Bitmap(Path.FullPath(@".\Resources\Pan2.png"));
     

  • Thursday, August 16, 2012 1:47 PM
     
     
    I am experiencing the exact same problem. In both cases I get the argumentException.

    yo