Load image file into int[]

Hi. I want to load an image. I would like support for png, jpeg, webp, bmp, and (if possible) gif. I found a good source for png (http://www.libpng.org/pub/png/spec/1.2/PNG-Structure.html), but nothing for the others. I don't want to use ImageIO then read from the buffered image, as that is slow. What I am asking for is how the bits of each type are laid out, so I can construct my own image loader. Also, the int[] is a flattened image, with the index of x and y being x + y * width. I am making my own window and game library, and don't want to use the stupidly slow java awt or java swing utilities. Please help.
8 Replies
JavaBot
JavaBot9mo ago
This post has been reserved for your question.
Hey @The Typhothanian! Please use /close or the Close Post button above when your problem is solved. Please remember to follow the help guidelines. This post will be automatically closed after 300 minutes of inactivity.
TIP: Narrow down your issue to simple and precise questions to maximize the chance that others will reply in here.
dan1st
dan1st9mo ago
If you write your own mechanism, it will likely be slower than ImageIO in most cases.
dan1st
dan1st9mo ago
you could try using https://stackoverflow.com/a/44170254/10871900 for making ImageIO faster
Stack Overflow
ImageIO.read(...) - It is very slow, is there a better way?
I am loading tons of icons that are going to be used in my application. I plan to load all of them from the jar on server startup. However, with hundreds of images adding up to just over 9MB, it is...
dan1st
dan1st9mo ago
Also make sure you are using the latest Java version
dan1st
dan1st9mo ago
JVM Gaming
Fastest Way to Load an Image?
I hate to make a blanket statement, but the default ImageIO stuff is notoriously slow. It’s only there because it’s a lot more convenient and clean to use. If you are just after loading PNG’s, Matthias posted up some custom code for loading those really quickly. Ask him about it. Jon
dan1st
dan1st9mo ago
or you could try one of the libraries here: https://www.baeldung.com/java-images
Baeldung
Working with Images in Java | Baeldung
A quick overview of several Java image-processing libraries, including a simple example done in all of them
dan1st
dan1st9mo ago
And if you are using something like LibGDX, use the APIs of that
JavaBot
JavaBot9mo ago
💤 Post marked as dormant
This post has been inactive for over 300 minutes, thus, it has been archived. If your question was not answered yet, feel free to re-open this post or create a new one. In case your post is not getting any attention, you can try to use /help ping. Warning: abusing this will result in moderative actions taken against you.
Want results from more Discord servers?
Add your server