The Source for Java Technology Collaboration

Home » java.net Forums » Java Desktop Technologies » JAI

Thread: Image watermarking with transparency

Welcome, Guest Help
Login Login
Guest Settings Guest Settings
This question is answered. Helpful answers available: 1. Correct answers available: 1.

Reply to this Thread Reply to this Thread Search Forum Search Forum Back to Thread List Back to Thread List

Permlink Replies: 4 - Last Post: Apr 23, 2008 5:04 PM by: bpb Threads: [ Previous | Next ]
abisola

Posts: 2
Image watermarking with transparency
Posted: Apr 22, 2008 4:53 AM
 
  Click to reply to this thread Reply

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.

haraldk

Posts: 12
Re: Image watermarking with transparency
Posted: Apr 22, 2008 8:32 AM   in response to: abisola
Helpful
  Click to reply to this thread Reply

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

abisola

Posts: 2
Re: Image watermarking with transparency
Posted: Apr 22, 2008 9:16 AM   in response to: haraldk
 
  Click to reply to this thread Reply

Thanks .k

Your code snippet was very helpful! I didn't need JAI afterall :)

You're a genius!

a.f.

bpb

Posts: 499
Re: Image watermarking with transparency
Posted: Apr 23, 2008 5:04 PM   in response to: abisola
 
  Click to reply to this thread Reply

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.

lfugaro

Posts: 9
Re: Image watermarking with transparency
Posted: Apr 23, 2008 12:39 AM   in response to: haraldk
 
  Click to reply to this thread Reply

Thanks, I needed it too!




 XML java.net RSS