Win a copy of TensorFlow 2.0 in Action this week in the Artificial Intelligence and Machine Learning forum!
  • 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 all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Liutauras Vilda
  • Paul Clapham
  • Bear Bibeault
  • Jeanne Boyarsky
Sheriffs:
  • Ron McLeod
  • Tim Cooke
  • Devaka Cooray
Saloon Keepers:
  • Tim Moores
  • Tim Holloway
  • Jj Roberts
  • Stephan van Hulst
  • Carey Brown
Bartenders:
  • salvin francis
  • Scott Selikoff
  • fred rosenberger

Help - watermark image using servlet

 
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.
 
Marshal
Posts: 67463
173
Mac Mac OS X IntelliJ IDE jQuery Java
  • 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
 
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/
 
I guess everyone has an angle. Fine, what do you want? Just know that you cannot have this tiny ad:
Building a Better World in your Backyard by Paul Wheaton and Shawn Klassen-Koop
https://coderanch.com/wiki/718759/books/Building-World-Backyard-Paul-Wheaton
reply
    Bookmark Topic Watch Topic
  • New Topic