Tutorial 2: Display A Picture Information: Labels Buttons
Tutorial 2: Display A Picture Information: Labels Buttons
information in a window. The picture information is: the image size in KB, the Width and the Length in pixels, the image format such as it is either a 24 bits per pixel RGB or 32 bppARGB with alpha byte or a byte per pixel 8bppIndexed with indexed table. You learn how to: Create a new project. Add basic controls like check boxes and buttons to a form. Add Open File dialog box to a form. Write event handler methods. When you finish, your program will look like the following picture.
Step 1: Create a Windows Forms Application Project. Set Your Form Properties. Step 2: Add Controls to Your Form. Add controls, such as a PictureBox , Labels and Buttons controls to your form. Rename your buttons to something more meaningful. Step 3: Add Dialog Components to Your Form. Add an OpenFileDialog component. Step 4: Write Code for the Show a Picture Button Event Handler. And run your program.
namespace ImageTry2 { public partial class Form1 : Form { public Form1() { InitializeComponent(); string loadedTrueImagePath int height, width; string pixelformat; Image loadedTrueImage ; ;
tbx_Image.Text = loadedTrueImagePath;
//or use imginf.FullName.ToString();
loadedTrueImage = Image.FromFile(loadedTrueImagePath); height = loadedTrueImage.Height; width = loadedTrueImage.Width ; pixelformat = loadedTrueImage.PixelFormat.ToString() ; FileInfo imginf = new FileInfo(loadedTrueImagePath); float fs = (float)imginf.Length / 1024; lblImageSize.Text = fs.ToString() + " KB"; lblImageHeight.Text = height.ToString() + " Pixel"; lblImageWidth.Text = loadedTrueImage.Width.ToString()+ "Pixel"; lblformat.Text = loadedTrueImage.PixelFormat.ToString(); lbltype.Text = imginf.Extension.ToString(); pictureBox1.Image = loadedTrueImage; this.Invalidate(); } } private void button1_Click(object sender, EventArgs e) { this.Close(); } } }