locked
System.Drawing Class and Bitmap Image Height and Width properties RRS feed

  • Question

  • I know this may sound a little dumb to you experienced coders but I'm having a we bit of a problem

    wtih figuring out what should be used in GDI+ when it comes to the average run of the mill images.

     

    The mini goal is to

    1.  Get a image- I did this

    2.  Get the width and height properties - not sure I did this - watch variables show the values though

    3.  Set the width and height properties in text boxes on a form - the compiler screams at me on this one

    4.  Display the image in a picturebox. - haven't left the starting gate on this one.

     

    Pretty simple it seemed.  The problem is that I've run into a dizzying array of information in the MSDN library.

    There seems to be Bitmap, BitmapInfo, & Image classes.  I'm not sure which one I use for the ultlimate task

    (for those of you who watched Hitchhikers Guide to the Galaxy!).  which is to

     

    1. read a directory of images,

    2. create an array of images with their properties,

    3. resize the images to something at or below the resolution of the end user's monitor,

    4. and then save the new images to a designated directory without changing the user's originals.

     

    Here's the earth shattering code:

     

    Bitmap bitImage = new Bitmap(@"C:\TEMP\Orion.jpg");      //This seems to work ok

    textBox2.Text = bitImage.Width;                                       //The compiler gets indigestion on these two lines;

    textBox1.Text = bitImage.Height;

    InitializeComponent();                                                       //This poor puppy never leaves the starting gate.

     

    I can see the Heigth and Width properties of the bitImage object in the Watch Window. 

    I cant get the values into the text boxes.  The error I get states "Cant convert int into string'. 

    There is a ToString in the Bitmap class but I cant figure out how to use it and the MSDN

    library doesn't seem to go into it in any detail.

     

    Any suggestions? 

     

    Thanks

    Tony

     

    ps

    After spending hours perusing the forums on GDI+  I hope to make reading my post a bit more enjoyable.  Smile

    Look forward to hearing from ya.

     

     

     

     

     

    Wednesday, May 16, 2007 5:11 AM

Answers

  • These are more basic c#/winforms problems...

    InitializeComponent is the method that will initialize your form (by calling all the controls on it it's constructor, setting these controls their properties, etc...), so it's the first thingyou want to do in a constructor...

    Once everything has been initialized, you can assign values to the controls properties... Since textBox.Text accepts strings, you'll have to make sure you assign it a string

    textBox2.Text = bitImage.Width.ToString(); /
    // since bitImage.Width is an int, you're using int.ToString method... not the bitmap.ToString method...
    Wednesday, May 16, 2007 6:25 AM
  • This will put the bitmap's height and width properties into textboxes:

    TextBox1.Text = Bmp.Width.ToString

    TextBox2.Text = Bmp.Height.ToString

    Wednesday, May 16, 2007 6:57 AM

All replies

  • These are more basic c#/winforms problems...

    InitializeComponent is the method that will initialize your form (by calling all the controls on it it's constructor, setting these controls their properties, etc...), so it's the first thingyou want to do in a constructor...

    Once everything has been initialized, you can assign values to the controls properties... Since textBox.Text accepts strings, you'll have to make sure you assign it a string

    textBox2.Text = bitImage.Width.ToString(); /
    // since bitImage.Width is an int, you're using int.ToString method... not the bitmap.ToString method...
    Wednesday, May 16, 2007 6:25 AM
  • This will put the bitmap's height and width properties into textboxes:

    TextBox1.Text = Bmp.Width.ToString

    TextBox2.Text = Bmp.Height.ToString

    Wednesday, May 16, 2007 6:57 AM
  • Timv and John W.

     

    Thanks to both.  Once I reversed the order the code worked.

    Go figure!

    Wednesday, May 16, 2007 12:18 PM