Image. An Image has a width and a height. With the Image type, found in System.Drawing, we load an image file and quickly determine these values.
Type notes. The Image type is an abstract data type that represents an image. It returns the data, Width and Height and other information about an image.
Example. To start, this program imports the System.Drawing namespace. If this creates an error, go to Add Reference to add the System.Drawing assembly.
Info Upon execution the program loads an image located in a specific file on the disk.
Note After Image.FromFile returns the Image reference, we can access the Width, Height and PhysicalDimension properties.
' Load Image from file.
Dim i As Image = Image.FromFile("C:\background1.png", False)
' Print dimensions of Image.
A discussion. Image does not handle all image formats, but it works on common ones such as PNG and JPG. We can use Image to read in width and height, and output that to HTML.
A summary. Image can be helpful for getting image information. Often height and width must be determined so that the data can correctly fit into the surrounding content or UI.
Dot Net Perls is a collection of tested code examples. Pages are continually updated to stay current, with code correctness a top priority.
Sam Allen is passionate about computer languages. In the past, his work has been recommended by Apple and Microsoft and he has studied computers at a selective university in the United States.
This page was last updated on Sep 28, 2022 (edit).