Reputation: 113
I'm trying to build a java servlet to obtain an image from an URL, check it's mime type and convert it if necessary, and then return that image. What objects should I use, can you provide me some examples specially for obtaining the image and returning it?
Thanks a lot
Upvotes: 0
Views: 1084
Reputation: 77104
Just use JAI (intro reference):
URL url = "// URL of the remote image to be read //";
RenderedImage original = JAI.create("url", url);
JAI.create("encode", original, response.getOutputStream(), "png");
Where response
is an HttpServletResponse
. Note that checking the mime-type isn't needed, JAI will do what's necessary to figure out how to read the image under the covers.
Upvotes: 1