Win a copy of Murach's Python Programming this week in the Jython/Python forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

Help - watermark image using servlet  RSS feed

 
Kavita Kale
Ranch Hand
Posts: 34
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hello,

In my project I want to display watermark image using servlet..
code written by me as below...
please tell me what is wrong it shows output as orignal image... & i want it to be a watermark..


package com.solversa;

import java.awt.AlphaComposite;
import java.awt.Composite;
import java.awt.Graphics;
import java.awt.Graphics2D;
import java.awt.image.BufferedImage;
import java.io.IOException;
import java.net.URL;
import javax.imageio.ImageIO;
import javax.servlet.*;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

public class kk extends HttpServlet

{
public void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException,IOException
{
doPost(request,response);
}

public void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException,IOException
{


URL url2 = new URL("http://weblogs.java.net/jag/Image54-large.jpeg");
BufferedImage im2 = ImageIO.read(url2);
Graphics g = im2.getGraphics();
Graphics2D g2d = (Graphics2D)g;
Composite originalComposite = g2d.getComposite();
g2d.setComposite(AlphaComposite.getInstance(AlphaComposite.SRC_OVER, 0.1f));
try
{

g2d.drawImage(im2,50,50,null);
g2d.dispose();

// remember to define your content type of your response
response.setContentType("image/jpeg");

// grab the servlet outputstream
ServletOutputStream out = response.getOutputStream();

// write your combined imaged to the response output stream
ImageIO.write( im2, "jpeg", out );

//display and close output stream
out.flush();
out.close();
}
catch(Exception e){}


}
}

urgent help required
Thank you,
kavita.
 
Bear Bibeault
Author and ninkuma
Marshal
Posts: 65826
134
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The image manipulation code really has nothing to do with servlets so this has been moved to the Other Java APIs forum.
 
Kavita Kale
Ranch Hand
Posts: 34
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hey ,,,
Anyone who know ... reply me

Kavita
 
Franz Allan See
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Good day,

I only see one image in your code ( most probably, it's the image you want to watermark ). So I'm guessing that's the problem.

Btw, you may want to use Watermarker to watermark your images ( see [1] ).

Cheers,
Franz

[1] http://code.google.com/p/watermarker/
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!