Results 1 to 4 of 4
  1. #1
    jeshmal4u is offline Member
    Join Date
    Mar 2010
    Posts
    5
    Rep Power
    0

    Unhappy 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.....

  2. #2
    toadaly is offline Senior Member
    Join Date
    Jan 2009
    Posts
    671
    Rep Power
    6

    Default

    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

    Java Code:
    import java.awt.*;
    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.

    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.

  3. #3
    jeshmal4u is offline Member
    Join Date
    Mar 2010
    Posts
    5
    Rep Power
    0

    Default

    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??


  4. #4
    toadaly is offline Senior Member
    Join Date
    Jan 2009
    Posts
    671
    Rep Power
    6

    Default

    Well, you're maknign progress. The excpetion is telling you where the problem is. Something at line 23 is null.

Similar Threads

  1. Struggling with OnKeyPressed Event in java
    By Camzie in forum NetBeans
    Replies: 2
    Last Post: 12-01-2009, 08:58 AM
  2. Struggling with java .ini files
    By Camzie in forum NetBeans
    Replies: 6
    Last Post: 11-24-2009, 04:13 PM
  3. struggling with creating a GUI
    By tuwannu in forum Advanced Java
    Replies: 2
    Last Post: 12-01-2008, 03:53 PM

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •