Results 1 to 6 of 6

Thread: [RESOLVED] Images

  1. #1

    Thread Starter
    Member
    Join Date
    Jun 2009
    Posts
    32

    Resolved [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.
    Last edited by michael1; Jul 28th, 2009 at 09:21 AM.

  2. #2
    PowerPoster 2.0 Negative0's Avatar
    Join Date
    Jun 2000
    Location
    Southeastern MI
    Posts
    4,367

    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

  3. #3
    PowerPoster stanav's Avatar
    Join Date
    Jul 2006
    Location
    Providence, RI - USA
    Posts
    9,289

    Re: Images

    Make sure the account that runs your application has write permission to that thumbnail directory too.
    Let us have faith that right makes might, and in that faith, let us, to the end, dare to do our duty as we understand it.
    - Abraham Lincoln -

  4. #4

    Thread Starter
    Member
    Join Date
    Jun 2009
    Posts
    32

    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?
    Last edited by michael1; Jul 28th, 2009 at 05:58 AM.

  5. #5
    PowerPoster 2.0 Negative0's Avatar
    Join Date
    Jun 2000
    Location
    Southeastern MI
    Posts
    4,367

    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?

  6. #6

    Thread Starter
    Member
    Join Date
    Jun 2009
    Posts
    32

    Re: Images

    Hi,
    thanks, It was just me being stupid. I had provied a directory for outputFile but no file! Thanks for your help.

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width