Skip to content

Conversation

@klatter
Copy link

@klatter klatter commented Aug 29, 2022

The current version of GetImageDimensions makes use of Java's BufferedImage, which loads the image uncompressed into memory. This can cause an out of memory exception using this java action with a a high resolution image.

The new implementation is based on the stackoverflow post below and avoids loading the image uncompressed into memory.
https://stackoverflow.com/questions/672916/how-to-get-image-height-and-width-using-java

// BEGIN USER CODE
ImageDimensions imageDimensions = new ImageDimensions(getContext());
try (InputStream inputStream = Core.getImage(getContext(), this.ImageParameter.getMendixObject(), false)) {
BufferedImage bimg = ImageIO.read(inputStream);
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The ImageIo.read method reads the whole inputstream.


try {
reader.setInput(imageStream);
int height = reader.getHeight(reader.getMinIndex());
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The PNG, JPG and BMP ImageReader implementations only read the imageheader to determine the height and width.

@sayyildiz sayyildiz force-pushed the master branch 2 times, most recently from ad750d8 to f63b15e Compare September 29, 2022 15:58
@atennapel atennapel force-pushed the master branch 2 times, most recently from fc75a53 to 14640f7 Compare August 22, 2023 14:22
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant