Forum Stats

  • 3,827,794 Users
  • 2,260,821 Discussions


How to create resized image instance from an existing image

wzberger Member Posts: 35
edited Sep 13, 2013 8:32AM in JavaFX 2.0 and Later

It looks like the image class does not provide a possibility to create a resized instance. Image#impl_getURL() would be good enough to create a resized instance of an existing image - but could be removed in a future release. So what's the preferred way if I have an image object only - there's no information about the based image resource.



  • James_D
    James_D Member Posts: 1,496 Gold Trophy

    You can resize an image on loading using one of the constructors that takes requestedWidth and requestedHeight parameters. This is useful for preserving memory when (for example) needing to display a large number of thumbnails.

    Additionally, the ImageView class defines resizing functionality for the view of an Image. So you can load the full Image, then display one or more resized versions in ImageView(s).

    If you need, you can retrieve an Image object representing the ImageView by calling snapshot(...) on the ImageView; for most use cases the ImageView itself will be all you need.

This discussion has been closed.