Skip to Main Content

Java SE (Java Platform, Standard Edition)

Announcement

For appeals, questions and feedback about Oracle Forums, please email oracle-forums-moderators_us@oracle.com. Technical questions should be asked in the appropriate category. Thank you!

Resize an image without reading it again from disk?

990159Feb 17 2013 — edited Feb 18 2013
0 down vote favorite


I need to resize an image based on it's longest side, e.g. longest side - which can be width or height - should be only 100 pixels long.

Currently I am using this method:
private Image resizeImageByLongestSide(File imageFile, int lengthLongestSide)
{
    String uri ="file:" + imageFile.getAbsolutePath();
    Image image = new Image(uri); // raed to determine width/height

    // read image again for resizing
    if(image.getWidth() >= image.getHeight())
        return new Image(uri, lengthLongestSide, 0, true, false);
    else
        return new Image(uri, 0, lengthLongestSide, true, false);
}
So, first the image has to be read by disk to figure out which side is the longest side, than it has again to be read from the disk, because resizing seems only possible by using the Image constructor... Any hint/improvement on this? Thanks :-)

Note: I already tried an ImageView for resizing the image, however [while an ImageView is not attached to a scene it seems not to resize the image|https://forums.oracle.com/forums/thread.jspa?threadID=2499808] ):

Comments

Locked Post
New comments cannot be posted to this locked post.

Post Details

Locked on Mar 18 2013
Added on Feb 17 2013
3 comments
90 views