Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

GetImageDimensions can crash Mendix app when processing high resolution images #126

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

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