Announcement

Collapse
No announcement yet.
X
  • Filter
  • Time
Clear All
new posts

    How to manipulate Image

    Hey folks,

    I have a new challenge for you. How to manipulate image?

    As a matter of fact, I need to render an image that should be picked in a list. There is a place where I will render it. But depending on the size of screen I need resize the image to accomodate it in its determinate area. My question is:
    How could I load the image, get its properties, like width and height in order to resize keeping its aspect ratio?
    I know that there is ImageResource and ClientBundle. But I did not get a way to load dynamic since these classes use @Source annotation in order to identify the resource.

    Waiting for ideas...

    #2
    Hi folks, I figured out how!

    Please, if this topic is useful for you, take a look below:

    Code:
    public void setPreviewImg(Image image) {
            
            // reading the current image dimensions
            int cwidth = image.getWidth();
            int cheight = image.getHeight();
            
            // getting the relative available space towards accommodate image
            int wavailable = formVorschau.getWidth();
            
            /* calculating the aspect ratio to arrange the image into the available space
             * this will keeps the image aspect without distortions
             */
            int nwidth = wavailable - 10;
            int nheight = ( ( cheight * nwidth ) / cwidth );
            
            // resizing the image
            image.setPixelSize(nwidth, nheight);
            
            // rendering the image
            formVorschau.addChild( image );
        }
    Bye for now!

    Vitor Eduardo

    Comment

    Working...
    X