Sign in to follow this  

[.net] PictureBox File Types

Recommended Posts

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,

// 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);



[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

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this