-
[RESOLVED] Images
Hi,
I have some code that allows the user to browse for an image and then when that image is opened, it is copied to a new directory. This all works fine, but I would like to know if there is a way to create a thumbnail of this image and save it into a subdirectory inside the directory where the original image has already been copied?
Also, I can't register my version of visual basic, so any help there might be useful. The link doesn't do anything.
-
Re: Images
Here is a function that will help you resize an image:
Code:
Private Sub Resize75Percent(ByVal inputFile As String, ByVal outputFile As String)
Dim input As Bitmap = New Bitmap(inputFile)
Dim x As Integer = Convert.ToInt32(input.Width * 0.75)
Dim y As Integer = Convert.ToInt32(input.Height * 0.75)
Dim output As Bitmap = New Bitmap(x, y, Imaging.PixelFormat.Format24bppRgb)
Dim g As System.Drawing.Graphics = Graphics.FromImage(output)
g.DrawImage(input, 0, 0, x, y)
output.Save(outputfile)
g.Dispose()
End Sub
-
Re: Images
Make sure the account that runs your application has write permission to that thumbnail directory too.
-
Re: Images
Hi,
everything works insofar as the code does successfully resize the image, however, When it tries to run the line "output.save(outputfile)" it presents this error, "A Generic error occured in GDI+". Please help, I've got no idea what it even means?
-
Re: Images
Do you have permission to write to the folder? You are not trying to overwrite the file that you have open as your input file, are you?
-
Re: Images
Hi,
thanks, It was just me being stupid. I had provied a directory for outputFile but no file! Thanks for your help.