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.
Imports System.Drawing
Module Module1
Sub Main()
' Load Image from file.
Dim i As Image = Image.FromFile("C:\background1.png", False)
' Print dimensions of Image.
Console.WriteLine(i.Width)
Console.WriteLine(i.Height)
Console.WriteLine(i.PhysicalDimension)
End Sub
End Module180
110
{Width=180, Height=110}
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 pages with code examples, which are updated to stay current. Programming is an art, and it can be learned from examples.
Donate to this site to help offset the costs of running the server. Sites like this will cease to exist if there is no financial support for them.
Sam Allen is passionate about computer languages, and he maintains 100% of the material available on this website. He hopes it makes the world a nicer place.
This page was last updated on Sep 28, 2022 (edit).