• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Help - watermark image using servlet

 
Ranch Hand
Posts: 34
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
Sheriff
Posts: 67749
173
Mac Mac OS X IntelliJ IDE jQuery TypeScript Java iOS
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hey ,,,
Anyone who know ... reply me

Kavita
 
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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/
 
I brought this back from the farm where they grow the tiny ads:
a bit of art, as a gift, the permaculture playing cards
https://gardener-gift.com
reply
    Bookmark Topic Watch Topic
  • New Topic