TheDeveloperBlog.com

Home | Contact Us

C-Sharp | Java | Python | Swift | GO | WPF | Ruby | Scala | F# | JavaScript | SQL | PHP | Angular | HTML

<< Back to VBNET

VB.NET Image Type

Use the Image type from the System.Drawing namespace to handle image files like PNGs.
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. We look at the specific VB.NET code for figuring out image dimensions.

Tip: The Image type is an abstract data type that represents an image. It returns Width and Height and other information about an image.

Also: The Image type stores the image's data in memory after it is read in from the disk.

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. Upon execution the program loads an image located in a specific file on the disk.
VB.NET program that opens Image 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 Module Output 180 110 {Width=180, Height=110}
After Image.FromFile returns the Image reference, we can access the Width, Height and PhysicalDimension properties. These tell us what the size of the image is. We do not need to read in the bytes from the image or anything else.

Warning: The Image type does not handle all image formats. It works on many popular formats such as PNG and JPG.

Summary. Often when developing programs that use image data, height and width must be determined so that the data can correctly fit into the surrounding content or UI. With the Image type in the System.Drawing namespace, this is possible.
© TheDeveloperBlog.com
The Dev Codes

Related Links:


Related Links

Adjectives Ado Ai Android Angular Antonyms Apache Articles Asp Autocad Automata Aws Azure Basic Binary Bitcoin Blockchain C Cassandra Change Coa Computer Control Cpp Create Creating C-Sharp Cyber Daa Data Dbms Deletion Devops Difference Discrete Es6 Ethical Examples Features Firebase Flutter Fs Git Go Hbase History Hive Hiveql How Html Idioms Insertion Installing Ios Java Joomla Js Kafka Kali Laravel Logical Machine Matlab Matrix Mongodb Mysql One Opencv Oracle Ordering Os Pandas Php Pig Pl Postgresql Powershell Prepositions Program Python React Ruby Scala Selecting Selenium Sentence Seo Sharepoint Software Spellings Spotting Spring Sql Sqlite Sqoop Svn Swift Synonyms Talend Testng Types Uml Unity Vbnet Verbal Webdriver What Wpf