Scale down the physical size of an image

  1. last week

    Tony L

    Dec 6 Pre-Release Testers, Xojo Pro Hong Kong

    Hi All,

    I have a desktop app that allows the user to save images to the database, the images are used to display on our website. I would like to scale down the image before it is saved. I know I can use the graphics class to reduce the size / resolution, but how can I reduce the dpi so that the physical size of the image can reduce further as I do not need to print it out, lower dpi does not affect the image shown on the website.

    Thanks in advance.

    Thanks Greg and Axel, it works for me.

  2. Emile S

    Dec 6 Europe (France, Strasbourg)

    Read the xxResolution Properties here .

    (New Picture at lower Resolution / draw larger image into the lower image / store the lower image)

  3. Greg O

    Dec 6 Xojo Inc Somewhere near Raleigh, NC

    @Tony L Hi All,

    I have a desktop app that allows the user to save images to the database, the images are used to display on our website. I would like to scale down the image before it is saved. I know I can use the graphics class to reduce the size / resolution, but how can I reduce the dpi so that the physical size of the image can reduce further as I do not need to print it out, lower dpi does not affect the image shown on the website.

    Thanks in advance.

    You do understand that lowering the dpi without changing the physical dimensions will actually increase the display size right?

    72px @ 72dots per inch = 1”
    72px @ 36 dots per inch = 2”

    My guess from your note is that sometimes you are getting images that are 300dpi. In that case, you’ll want to do some math...

    dim p as picture = original
    dim sf as double = 72 / 300
    Dim newpic as new picture(p.width*sf, p.height*sf)

    Draw the picture onto that new image. It defaults to 72x72 dpi so you’ll get what you’re looking for.

  4. Tony L

    Dec 6 Pre-Release Testers, Xojo Pro Hong Kong

    Hi Greg,

    I tried with your suggested math calculation:

    dim p as picture = image1.Image //i have an image that allow file drop without any resizing
    dim sf as double = 72 / 300
    Dim newpic as new picture(p.width*sf, p.height*sf)
    
    //how do I assign the picture content of p to new pic?
    
    dim folder as new FolderItem
    dim file as new FolderItem
    folder.name = "c:\temp"
    file = folder.child("test.jpg")
    
    newpic.Save(file, picture.SaveAsJPEG)

    How do I assign the picture content of p to new pic?

  5. Axel S

    is not verified Dec 6 Europe (Germany, Erfurt)

    quickly out of my memory

    Dim newpic as new picture(p.width*sf, p.height*sf)
    newpic.Graphics.DrawPicture(p, 0, 0, p.Width * sf, p.Height * sf, 0, 0, p.Width, p.Height)
  6. 7 days ago

    Tony L

    Dec 7 Pre-Release Testers, Xojo Pro Answer Hong Kong

    Thanks Greg and Axel, it works for me.

or Sign Up to reply!