Reputation: 159
How do I resize to 100px by 100px and save the image in picturebox as a PNG? I can do the saving but the output file won't open. The code I only have is below.
picbox.Image.Save("example_file", System.Drawing.Imaging.ImageFormat.Png)
Upvotes: 2
Views: 6004
Reputation: 38905
The basics for a thumbnail are fairly straight forward:
For saving, you might want to add ".png" to the filename. Since your image is in a picbox, get it out for less typing:
Dim bmp As Bitmap = CType(picbox.Image, Bitmap)
' bmpt is the thumbnail
Dim bmpt As New Bitmap(100, 100)
Using g As Graphics = Graphics.FromImage(bmpt)
' draw the original image to the smaller thumb
g.DrawImage(bmp, 0, 0,
bmpt.Width + 1,
bmpt.Height + 1)
End Using
bmpt.Save("example_file.PNG", System.Drawing.Imaging.ImageFormat.Png)
Notes:
Bitmap
you create must be disposed of when you are done with it.
bmpt.Dispose()
as the last line.PictureBox
) you wont be able to save to the same file name. Alter the name slightly such as "myFoo" saved as "myFoo_t".Bitmap
from the other.Upvotes: 2