www.JohnJustin.tk
TECH A BREAK 2010 PHOTOS
friendsclub academic project
librarymanagementsystem
AirwayReservationsystem
Payroll Calculation Project
Online Banking project
DOWNLOAD 125 JAVA PROJECTS FREE
FREE DOWNLOAD KAROAKE
FOR ADVERTISE HERE
CONTACT 917667566149

Thursday, June 24, 2010

how to do watermarking on images using java and jsp

watermarking on jep using jsp or java free source code of java watermarking on images(bmp,jpeg,png)


dear friends we can make watermarking on images or logos using java .this code is useful for somebody want to write their logo or their company name on their images published on their website.this watermarking code is free and you can use this code for education purpose only. this watermarking code can be applied on jsp also.

/**
* @author John.J
www.johnjustin.tk
*
*/

 

import java.awt.AlphaComposite;
import java.awt.Color;
import java.awt.Font;
import java.awt.Graphics;
import java.awt.Graphics2D;
import java.awt.Image;
import java.awt.image.BufferedImage;
import java.io.File;
import java.io.FileOutputStream;
import java.util.Random;

import javax.imageio.ImageIO;
import javax.swing.ImageIcon;

import com.sun.image.codec.jpeg.JPEGCodec;
import com.sun.image.codec.jpeg.JPEGEncodeParam;
import com.sun.image.codec.jpeg.JPEGImageEncoder;

public class Watermark
{
public static void main(String[] args)
{
try
{
Font font;
File _file = new File("C:/car.jpg");
Image src = ImageIO.read(_file);
int width = src.getWidth(null);
int height = src.getHeight(null);
System.out.println("X = "+width+" and Y = "+height);
BufferedImage image = new BufferedImage(width, height
, BufferedImage.TYPE_INT_RGB);
Graphics g = image.createGraphics();
g.drawImage(src, 0, 0, width, height, null);
// g.setBackground(Color.white);
g.setColor(Color.red);
g.setFont(new Font("Verdana", Font.BOLD, 20));

g.drawString("www.johnjustin.tk", 5, height - (new
Font("Arial", Font.BOLD, 20)).getSize() / 2 - 5);
g.dispose();

FileOutputStream out = new FileOutputStream("C:/car2.jpg");
JPEGImageEncoder encoder = JPEGCodec.createJPEGEncoder(out);
encoder.encode(image);
out.close();
} catch (Exception ee)
{
System.out.println("Error Occurred : "+ee);
}
}
}



how to use this code?
copy the input image to here car.jpg in your hard disk here iam copying car.jpg in c drive
write your watermarking inside
g.drawString("www.johnjustin.tk", 5, height - (new Font("Arial", Font.BOLD, 20)).getSize() / 2 - 5);


you can specify the color and font size inside the g.drawstring method

the image before water marking using java is below



watermarkinginjava

after adding watermark see the given figure below
watermarkinginjava

1 comments:

hello. Can you make watermarking for video, her special mpg video format? thank you

JohnJustin
software engineer,blogger,writer,prolife worker and an active JesusYouth
johnjustin@in.com
TECH A BREAK 2010 PHOTOS
friendsclub academic project
librarymanagementsystem
AirwayReservationsystem
Payroll Calculation Project
Online Banking project
DOWNLOAD 125 JAVA PROJECTS FREE
FREE DOWNLOAD KAROAKE
FOR ADVERTISE HERE
CONTACT 917667566149

.
.
.

Subscribe feeds via e-mail
Subscribe in your preferred RSS reader

Subscribe feeds rss Recent Entries

Advertise on this site Sponsored links

Categories

Sponsored Links

.
TECH A BREAK 2010 PHOTOS
friendsclub academic project
librarymanagementsystem
AirwayReservationsystem
Payroll Calculation Project
Online Banking project
DOWNLOAD 125 JAVA PROJECTS FREE
FREE DOWNLOAD KAROAKE
FOR ADVERTISE HERE
CONTACT 917667566149

.

My Photos on flickr

Subscribe feeds rss Recent Comments

Technorati

Technorati
My authority on technorati
Add this blog to your faves