0% found this document useful (0 votes)
34 views

Tutorial 2: Display A Picture Information: Labels Buttons

The document describes building a program that loads an image and displays information about it. It explains how to create a Windows Forms project, add controls like buttons and labels to display image details, add an Open File dialog to load an image, and write code to display the image size, dimensions, and format when a button is clicked.
Copyright
© Attribution Non-Commercial (BY-NC)
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
34 views

Tutorial 2: Display A Picture Information: Labels Buttons

The document describes building a program that loads an image and displays information about it. It explains how to create a Windows Forms project, add controls like buttons and labels to display image details, add an Open File dialog to load an image, and write code to display the image size, dimensions, and format when a button is clicked.
Copyright
© Attribution Non-Commercial (BY-NC)
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 3

Tutorial 2: Display a Picture information In this tutorial, you build a program that loads a picture and displays its

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.

Dr. Mohammed Fadhl

Computer Graphic Lab

using using using using using using using using

System; System.Collections.Generic; System.ComponentModel; System.Data; System.Drawing; System.Text; System.Windows.Forms; System.IO;

namespace ImageTry2 { public partial class Form1 : Form { public Form1() { InitializeComponent(); string loadedTrueImagePath int height, width; string pixelformat; Image loadedTrueImage ; ;

private void EnImageBrowse_btn_Click(object sender, EventArgs e) { if (openFileDialog1.ShowDialog() == DialogResult.OK) { loadedTrueImagePath = openFileDialog1.FileName;


Dr. Mohammed Fadhl Computer Graphic Lab 2

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(); } } }

Dr. Mohammed Fadhl

Computer Graphic Lab

You might also like