• Advertisement
Sign in to follow this  

[.net] PictureBox File Types

This topic is 3730 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

What file types can a PictureBox handle intuitively? Is there a way to make the class handle more image types? [Edited by - EmrldDrgn on January 31, 2008 7:35:57 PM]

Share this post


Link to post
Share on other sites
Advertisement
From the help files: "Typically the PictureBox is used to display graphics from a bitmap, metafile, icon, JPEG, GIF, or PNG file."

But you can create any converter you wish so that it supports any file type, that is the beauty of being a programmer :)

You set it via the Image property which is an Image class object. So any picture you plan on putting into the box must be made into an Image.

The nice thing about this is that a Bitmap class object inherits from the Image class object so you can assign a Bitmap to that property as well. Further more the Bitmap allows you to set it's pixels to whatever color you want via the SetPixel method. The following is a way to play around with the color of the Bitmap's pixels. And what I'm getting at is that from this you can really convert any file format once loaded into memory. Again from the help:


public void SetPixel_Example(PaintEventArgs e)
{

// Create a Bitmap object from a file.
Bitmap myBitmap = new Bitmap("Grapes.jpg");

// Draw myBitmap to the screen.
e.Graphics.DrawImage(myBitmap, 0, 0, myBitmap.Width,
myBitmap.Height);

// Set each pixel in myBitmap to black.
for (int Xcount = 0; Xcount < myBitmap.Width; Xcount++)
{
for (int Ycount = 0; Ycount < myBitmap.Height; Ycount++)
{
myBitmap.SetPixel(Xcount, Ycount, Color.Black);
}
}

// Draw myBitmap to the screen again.
e.Graphics.DrawImage(myBitmap, myBitmap.Width, 0,
myBitmap.Width, myBitmap.Height);
}





HTH,

Devin

[edit] I should have noted that you can also create a Graphics object from the Bitmap as well via the:


Graphics gr = Graphics.FromBitmap(myBitmap);

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement