|
|
|
|
Image watermarking with transparency
Posted:
Apr 22, 2008 4:53 AM
|
|
|
Hi guys,
I'm a newbie to JAI and need to implement a watermarking functionality. I have a logo (png) which I intend to use as a watermark on my photos that I post online (jpegs). I want the logo to be just slightly visible on my pictures.
Can someone please give me pointers on how I can achieve this? I've trawled around on the forums a bit but still no joy.
|
|
|
|
|
|
|
Re: Image watermarking with transparency
Posted:
Apr 22, 2008 8:32 AM
in response to: abisola
|
 |
Helpful |
|
|
You might not need JAI at all. But something like this is a perfectly suitable naive implementaiton:
File waterMarkFile; File inputFile; File outputFile;
BufferedImage waterMark = ImageIO.read(waterMarkFile);
// You probably want to loop the rest if you have many images BufferedImage image = ImageIO.read(inputFile); Graphics2D g = image.createGraphics(); try { g.setComposite(AlphaComposite.getInstance(AlphaComposite.SRC_OVER, 0.5f));// 50% transp g.drawImage(waterMark, image.getWidth() - waterMark.getWidth(), image.getHeight() - waterMark.getHeight(), null);// draw in lower right corner } finally { g.dispose(); } ImageIO.write(image, outputFile);
Regards,
.k
|
|
|
|
|
|
|
|
Re: Image watermarking with transparency
Posted:
Apr 22, 2008 9:16 AM
in response to: haraldk
|
|
|
Thanks .k
Your code snippet was very helpful! I didn't need JAI afterall 
You're a genius!
a.f.
|
|
|
|
|
|
|
|
Re: Image watermarking with transparency
Posted:
Apr 23, 2008 5:04 PM
in response to: abisola
|
|
|
This raises a good point. While we would love you to use JAI (or JAI Image I/O Tools), if there is no point in doing so and you can get away with what Java 2D (or core Java Image I/O) has to offer. It is also better to have a thorough understanding of these core APIs before moving to the optional packages.
Brian
> Thanks .k > > Your code snippet was very helpful! I didn't need JAI > afterall  > > You're a genius! > > a.f.
|
|
|
|
|
|
|
|
Re: Image watermarking with transparency
Posted:
Apr 23, 2008 12:39 AM
in response to: haraldk
|
|
|
Thanks, I needed it too!
|
|
|
|
|