We are about to switch to a new forum software. Until then we have removed the registration on this forum.
Hi everyone,
I'm trying to figure out an efficient way to get a comment from the end of a png image file. It's near the end of the file, so I would like to work backwards from the end instead of starting at the beginning and parsing through all the image data.
General algorithm would be: 1) open the file 2) seek to the end 3) search backwards for "%tEXt Comment " 4) read forwards for comma separated fields of numbers and text 5) somehow parse out that info. Mainly what I need is the first number, which can be 0 through 12, and convert it from ascii digits to a number.
It'd be easy for me to figure out how to do it in C, but I'm not sure how to seek to the end and then search backwards. Is that possible? I've done some online searching and have gotten to the relevant data by searching forward, but I would like to do it more efficiently than reading through everything since I'll be working with multiple images.
Any tips would be appreciated.
Answers
Maybe the function
seek
in RandomAccessFile.Note that questions such as these are not specific to Processing, hence a quick Google search for Java will tend to yield required results.
See also discussion:
Thanks for all the replies! Those are all great leads.
I ended up using a RandomAccessFile, seeking to a particular spot from the end of the file so that I wouldn't need to search through the entire file. Then I scanned for what I was looking for.
Can you post your code..?
I'll ask. I may not be able to due to my contract.
Thanks for sharing your approach.
For other forum users:
https://docs.oracle.com/javase/7/docs/api/java/io/RandomAccessFile.html