T
the.trav
I've got a little app that loads a jpeg from an input stream, stamps it
with a png it loaded earlier, then writes the modified jpeg to an
output stream.
It's all working and rosy, however I'm not sure it's quite as efficient
as it could be.
The basic technique I've got is to use ImageIO.read(inputStream) to get
a BufferedImage of each of the original files,
Then I create a new BufferedImage that supports alpha transparancy,
getGraphics then drawImage to draw the original, then drawImage again
to draw the watermark on top of the orginal.
Then I create a final BufferedImage that doesn't support any
transparancy and draw the stamped bufferedImage to it.
Finally I write the final bufferedImage to the output stream using
ImageIO.write(image, out);
It strikes me that I'm creating one more BufferedImage than is
necessary here,
however if I try to write the second last buffered image (the one with
alpha) to the outstream it comes out faded and with different colour
information.
If I make that buffered image without alpha to start the colour
information is correct, but the watermark is 100% opaque (binary
transparancy).
I haven't been able to find a way to convert the colour model in a
buffered image yet, and I would have thought that ImageIO could convert
it a lot better than it is doing.
I also looked into imageTranscoders, however my jre tells me that there
are no elements in the Iterator ImageIO.getImageTranscoders(pngReader,
jpegWriter);
I have also had great difficulty finding documentation on the subject
as most of the tutorials google brings back are task specific and
relate to rendering to the screen for applets and games and so forth.
with a png it loaded earlier, then writes the modified jpeg to an
output stream.
It's all working and rosy, however I'm not sure it's quite as efficient
as it could be.
The basic technique I've got is to use ImageIO.read(inputStream) to get
a BufferedImage of each of the original files,
Then I create a new BufferedImage that supports alpha transparancy,
getGraphics then drawImage to draw the original, then drawImage again
to draw the watermark on top of the orginal.
Then I create a final BufferedImage that doesn't support any
transparancy and draw the stamped bufferedImage to it.
Finally I write the final bufferedImage to the output stream using
ImageIO.write(image, out);
It strikes me that I'm creating one more BufferedImage than is
necessary here,
however if I try to write the second last buffered image (the one with
alpha) to the outstream it comes out faded and with different colour
information.
If I make that buffered image without alpha to start the colour
information is correct, but the watermark is 100% opaque (binary
transparancy).
I haven't been able to find a way to convert the colour model in a
buffered image yet, and I would have thought that ImageIO could convert
it a lot better than it is doing.
I also looked into imageTranscoders, however my jre tells me that there
are no elements in the Iterator ImageIO.getImageTranscoders(pngReader,
jpegWriter);
I have also had great difficulty finding documentation on the subject
as most of the tutorials google brings back are task specific and
relate to rendering to the screen for applets and games and so forth.