VB.NET || How To Resize & Rotate Image, Convert Image To Byte Array, Change Image Format, & Fix Image Orientation Using VB.NET

Print Friendly, PDF & Email

The following is a module with functions which demonstrates how to resize an image, rotate an image to a specific angle, convert an image to a byte array, change an image format, and fix an image orientation Using VB.NET.

Note: To use the functions in this module, make sure you have a reference to ‘System.Drawing‘ in your project.

One way to do this is, in your Solution Explorer (where all the files are shown with your project), right click the ‘References‘ folder, click ‘Add References‘, then type ‘System.Drawing‘ in the search box, and add a reference to System.Drawing in the results Tab.


1. Resize & Rotate – Image

The example below demonstrates the use of ‘Utils.Image.Resize‘ and ‘Utils.Image.Rotate‘ to resize and rotate an image object.

Resizing and rotating an image returns a newly created image object.


2. Resize & Rotate – Byte Array

The example below demonstrates the use of ‘Utils.Image.Resize‘ and ‘Utils.Image.Rotate‘ to resize and rotate a byte array.

Resizing and rotating an image returns a newly created image object.


3. Resize & Rotate – Memory Stream

The example below demonstrates the use of ‘Utils.Image.Resize‘ and ‘Utils.Image.Rotate‘ to resize and rotate a memory stream.

Resizing and rotating an image returns a newly created image object.


4. Convert Image To Byte Array

The example below demonstrates the use of ‘Utils.Image.ToArray‘ to convert an image object to a byte array.

The optional function parameter allows you to specify the image format.


5. Change Image Format

The example below demonstrates the use of ‘Utils.Image.ConvertFormat‘ to convert the image object raw format to another format.

Converting an images format returns a newly created image object.


6. Fix Image Orientation

The example below demonstrates the use of ‘Utils.Image.FixOrientation‘ to update the image object to reflect its Exif orientation.

When you view an image in a Photo Viewer, it automatically corrects image orientation if it has Exif orientation data.

Utils.Image.FixOrientation‘ makes it so the loaded image object reflects the correct orientation when rendered according to its Exif orientation data.


7. Utils Namespace

The following is the Utils Namespace. Include this in your project to start using!


8. More Examples

Below are more examples demonstrating the use of the ‘Utils‘ Namespace. Don’t forget to include the module when running the examples!

QUICK NOTES:
The highlighted lines are sections of interest to look out for.

The code is heavily commented, so no further insight is necessary. If you have any questions, feel free to leave a comment below.

Leave a Reply