Results 1 to 4 of 4
- 03-07-2010, 07:20 AM #1
Member
- Join Date
- Mar 2010
- Posts
- 5
- Rep Power
- 0
Struggling with AlphaComposite .. please help me
import java.awt.Color;
//import java.awt.Font;
import java.awt.Graphics2D;
import java.awt.RenderingHints;
//import java.awt.font.FontRenderContext;
import java.awt.geom.Rectangle2D;
import java.awt.image.BufferedImage;
import java.io.File;
import java.io.IOException;
import javax.imageio.ImageIO;
class watermark2
{
public static void main(String args[])
{
BufferedImage image1= null;
BufferedImage image2= null;
File file = new File("./" + "captcha" + ".jpeg");
BufferedImage captcha= null;
image1 = ImageIO.read(new File("bug2.gif"));
captcha = ImageIO.read(new File("pass.jpeg"));
//BufferedImage image = ImageIO.read(inputFile);
Graphics2D g = image1.createGraphics();
try {
g.setComposite(AlphaComposite.getInstance(AlphaCom posite.SRC_OVER, 0.5f));// 50% transp
g.drawImage(captcha, image1.getWidth() - captcha.getWidth(), image1.getHeight() - captcha.getHeight(), null);// draw in lower right corner
}
finally {
g.dispose();
}
ImageIO.write(image1,"jpeg",file);
}
}
There is a error in my above code saying "cannot resolve symbol, variable:AlphaComposite"..
please help me.....
- 03-07-2010, 07:37 AM #2
Senior Member
- Join Date
- Jan 2009
- Posts
- 671
- Rep Power
- 5
You have not imported java.awt.AlphaComposite. Maybe I'm just lazy, but I have a tendency to make my import statements broad, such as
This is generally considered poor practice, but I've been programming java for 15 years now, and have concluded there is no real value to importing a single class at a time. There is no measurable increase in compile-time, nor run-time to use broad import statements, it cuts down on the lines of code, and there are no debugging or maintenance drawbacks that are not also present with class-by-class import statements.Java Code:import java.awt.*;
The only downside is an increase in the number of vague references, which must then be resolved using greater specificity. The most common being that when you import both java.awt.* and java.util.*, List exists in both packages.
- 03-07-2010, 07:43 PM #3
Member
- Join Date
- Mar 2010
- Posts
- 5
- Rep Power
- 0
now i did as you say.. now it's showing exceptions.. This 1st image shows the exeption before adding a try catch.. 2nd one is after adding try catch.. nbow what to do??

- 03-08-2010, 05:11 AM #4
Senior Member
- Join Date
- Jan 2009
- Posts
- 671
- Rep Power
- 5
Similar Threads
-
Struggling with OnKeyPressed Event in java
By Camzie in forum NetBeansReplies: 2Last Post: 12-01-2009, 07:58 AM -
Struggling with java .ini files
By Camzie in forum NetBeansReplies: 6Last Post: 11-24-2009, 03:13 PM -
struggling with creating a GUI
By tuwannu in forum Advanced JavaReplies: 2Last Post: 12-01-2008, 02:53 PM


LinkBack URL
About LinkBacks
Reply With Quote

Bookmarks