Coding Challenge: Fast Width/Height of an Image
Coding Challenge: Fast Width/Height of an Image
Join the DZone community and get the full member experience.
Join For FreeJava-based (JDBC) data connectivity to SaaS, NoSQL, and Big Data. Download Now.
I am trying to find out the width and height of an image (a URL) transferring as few bytes as possible. This coding challenge has two separate parts:
- Finding the cheapest way to retrieve width and height.
- Verifying that the solution is indeed cheap.
The first part is not that interesting since it’s a fairly well documented problem. A bit too documented, actually, since I found several solutions:
- A naïve version using ImageIO.
- A more advanced solution using ImageReaders.
- A hand rolled solution written by Jaimon Matthew.
This last solution looks pretty efficient from a network perspective but I’m worried it might leave out a few corner cases in image handling. The first two solutions are probably battle tested and very robust but I have no idea how effective they are from a network standpoint (their Javadoc doesn’t describe the specifics of how they operate).
So… Do you have a better solution? And whether you do or don’t, how would you assess how many bytes these implementations transfer?
Connect any Java based application to your SaaS data. Over 100+ Java-based data source connectors.
Published at DZone with permission of Cedric Beust , DZone MVB. See the original article here.
Opinions expressed by DZone contributors are their own.
{{ parent.title || parent.header.title}}
{{ parent.tldr }}
{{ parent.linkDescription }}
{{ parent.urlSource.name }}