Here a detailed tutorial on how to successfully resize an image.
●First of all you do not do this:
John has an image with the dimensions 300 x 200 and he wants to increase each by 100. He loads an image into a picturebox and does the following:
Code:
PictureBox1.Size = New Size(400, 300)
PictureBox1.Image.Save("Cute Dog.png")
It will not work since the save functions saves the image as it is and also John does not know Visual Basic.
__________________________________________________ _____________________________________________
And now lets get to what you should do.
●First of all we need to import namespace 'Drawing' which has some handy elements such as classes, functions etc.
Code:
Imports System.Drawing
●Now lets create the function that will resize the image you want with the the original image and the new size as input.
Code:
Function ResizeImage(Byval Image As Image, Byval NewSize As Size) As Image
●Create a new blank bitmap.
Code:
Dim _Image As Image = New Bitmap(NewSize)
●Now create the graphics handle to the image.
Code:
Dim _Graphics As Graphics = Graphics.FromImage(_Image)
●Now we draw the original image onto to the blank bitmap using the handle.
Code:
_Graphics.DrawImage(Image, 0, 0, Size.Width, Size.Height)
●Now to end the function.
●Heres the code in actions:
You have an image of 400 x 50 and want to change the dimensions to 200 x 50. So heres what you can do:
Code:
PictureBox1.Image = ResizeImage(My.Resources.MyImage, New Size(200 x 50))
PictureBox1.Imge.Save("Cute Dog.png")
And thats all.