Image resize(scale) with slider

  1. 3 months ago

    I have a method to scale an image. It's for a canvas, so I have to think about how to transfer that to a listbox column first and foremost.
    Once I figure that out, how do I go about adding that functionality to a slider?
    I want the slider to not only adjust the listbox row heights, which I already have, but to have the image scale along with the row.

  2. Ivan T

    May 15 Pre-Release Testers

    Store the original image, when the slider move, resize the picture and save it in a cache, then just invalidate the listbox and draw the cached image.

    https://www.google.com/search?q=xojo+image+in+listbox

  3. @Ivan T Store the original image, when the slider move, resize the picture and save it in a cache, then just invalidate the listbox and draw the cached image.

    https://www.google.com/search?q=xojo+image+in+listbox

    I've obviously used Google already. Perhaps linking to an actual article?

  4. Ivan T

    May 15 Pre-Release Testers
    Edited 3 months ago

    Only in the the very first result in google you can find: some code, 2 reference to the documentation and 2 webinars

    https://forum.xojo.com/2499-image-in-listbox/0

    Also searching for "xojo resize image", the first result:

    https://forum.xojo.com/24623-picture-scale-to-fit-width-height-of-imagewell/0

  5. Sam R

    May 15 Pre-Release Testers, Xojo Pro Hengchun, Pingtung, Taiwan

    Resizing an image in the paint event of a control is not optimal, especially if it's a large image. Modern versions of the macOS will cache that resized version, but you have zero control over it and it can lead to some funky issues. Also if drawing takes too long, the macOS will get antsy and log errors; often it also unlocks the context prematurely leading to weird graphic issues. Which is absolutely horrific considering Apple love using lazy loading, and refuse to load the actual image data until it's drawn. This inconsistency kind of crap drives me nuts.

    In an ideal situation you already know what the maximum size variation is, so when you open the image, you create a new image at that size and draw your image into that size. This serves two purposes, number 1, it ensures the image is loaded into memory (Lazy loading, get lost) and secondly you now have a image that's guaranteed to be no bigger than your maximum size.

    Then you create a variation that's the smallest size you're going to draw; and a bunch of variations in-between.

    Once you have your variations, you can then create a new picture from all these variations.
    https://docs.xojo.com/Picture.Constructor(width_as_Integer,_height_as_Integer,_bitmaps()_As_Picture )

    Now when you draw this picture, the OS is going to pick the most appropriate sized image when drawing, giving you the best performance across all platforms. Yes it's more work, but to do things in an optimized way always are.

or Sign Up to reply!