Welcome to the Java Programming Forums


The professional, friendly Java community. 21,500 members and growing!


The Java Programming Forums are a community of Java programmers from all around the World. Our members have a wide range of skills and they all have one thing in common: A passion to learn and code Java. We invite beginner Java programmers right through to Java professionals to post here and share your knowledge. Become a part of the community, help others, expand your knowledge of Java and enjoy talking with like minded people. Registration is quick and best of all free. We look forward to meeting you.


>> REGISTER NOW TO START POSTING


Members have full access to the forums. Advertisements are removed for registered users.

Results 1 to 5 of 5

Thread: Need help with extracting AlphaComposite from an image

  1. #1
    Junior Member
    Join Date
    Nov 2012
    Posts
    3
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Question Need help with extracting AlphaComposite from an image

    Hi, i'm currently working on a watermark that is invisible using AlphaComposite class. The problem i'm having now is that i'm unable to extract the watermark out from the image after it is save.

    package invisibleWatermark;
     
    import java.awt.*;
    import java.awt.geom.*;
    import java.awt.image.*;
     
    import java.io.*;
     
     
    import javax.imageio.*;
     
    import javax.swing.*;
     
    public class watermark {
     
    	static BufferedImage bufferedImage;
     
     
    	static void watermark(){
     
    		File upImage = new File(mainMenu.txtLoadImage.getText());
     
    		if(!upImage.exists()){
    			JOptionPane.showMessageDialog(null, "Please Select an image to be watermark. "); 
    		}
    		else {
     
    			if (mainMenu.txtInputWatermark.getText().isEmpty()){
    				JOptionPane.showMessageDialog(null, "Please select a watermark to be use. "); 
     
    				return; 
    			}
    			else{
    				ImageIcon oriImage = new ImageIcon(upImage.getPath()); 
     
    				bufferedImage = new BufferedImage(oriImage.getIconWidth(), oriImage.getIconHeight(), BufferedImage.TYPE_INT_RGB);
     
    		        Graphics2D g2D = (Graphics2D) bufferedImage.getGraphics();
     
    		        g2D.drawImage(oriImage.getImage(), 0, 0, null);
     
    	            AlphaComposite alpha = AlphaComposite.getInstance(AlphaComposite.SRC_OVER, 0.1f);
     
    	            g2D.setComposite(alpha);
    	            g2D.setColor(Color.white);
    	            g2D.setRenderingHint(RenderingHints.KEY_TEXT_ANTIALIASING, RenderingHints.VALUE_TEXT_ANTIALIAS_ON);
    	            g2D.setFont(new Font("Arial", Font.BOLD, 35));
     
    	            String watermark = mainMenu.txtInputWatermark.getText();
     
    	            FontMetrics fontMetrics = g2D.getFontMetrics();
     
    	            Rectangle2D rect2D = fontMetrics.getStringBounds(watermark, g2D);
     
    	            g2D.drawString(watermark, (oriImage.getIconWidth() - (int) rect2D
    	                            .getWidth()) / 2, (oriImage.getIconHeight() - (int) rect2D
    	                            .getHeight()) / 2);
     
    	            g2D.dispose();
     
    	            embedPopupMenu.embedConfirmMenu(); 
    			}
    		}
    	}
    }


  2. #2
    Super Moderator jps's Avatar
    Join Date
    Jul 2012
    Posts
    2,642
    My Mood
    Daring
    Thanks
    90
    Thanked 263 Times in 232 Posts

    Default Re: Need help with extracting AlphaComposite from an image

    Welcome zwei_91

    What do you mean by "unable to extract"?
    What happens and what does not happen? What do you expect instead?

  3. #3
    Junior Member
    Join Date
    Nov 2012
    Posts
    3
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: Need help with extracting AlphaComposite from an image

    Quote Originally Posted by jps View Post
    Welcome zwei_91

    What do you mean by "unable to extract"?
    What happens and what does not happen? What do you expect instead?
    Hi jps,

    Basically i'm creating an application that enable watermark to be embedded invisibly on images, the code above enable me to do that.

    But then the other problem i'm having now is that after embedding the watermark invisibly, i'm unable to extract it for verification purpose.

    By the way, sorry for my bad English.

  4. #4
    Super Moderator jps's Avatar
    Join Date
    Jul 2012
    Posts
    2,642
    My Mood
    Daring
    Thanks
    90
    Thanked 263 Times in 232 Posts

    Default Re: Need help with extracting AlphaComposite from an image

    Does the code compile?
    Is there an error?
    Is the output wrong?
    Do you even get output?
    What happens and what does not happen, on a more specific level than "extracting watermarks".

    Your English is better than my German I promise

  5. #5
    Junior Member
    Join Date
    Nov 2012
    Posts
    3
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: Need help with extracting AlphaComposite from an image

    Quote Originally Posted by jps View Post
    Does the code compile?
    Is there an error?
    Is the output wrong?
    Do you even get output?
    What happens and what does not happen, on a more specific level than "extracting watermarks".

    Your English is better than my German I promise
    1. Yes, the code compile
    2. No, there is no error
    3. No, the output is correct
    4. Yes, i got the desire output
    5. Problem i'm facing now is that i'm unable to undo the process that the code above perform from the output file save

Similar Threads

  1. [SOLVED] Extracting whole number digits from a float
    By Johnny Bravo in forum Algorithms & Recursion
    Replies: 2
    Last Post: August 12th, 2012, 04:04 PM
  2. Problem extracting data from file
    By hello_world in forum File I/O & Other I/O Streams
    Replies: 17
    Last Post: August 21st, 2011, 09:35 PM
  3. hello help me in extracting my program
    By mak991 in forum Java Theory & Questions
    Replies: 1
    Last Post: June 16th, 2011, 08:06 AM
  4. Extracting letters as variables
    By TH1 in forum Java Theory & Questions
    Replies: 3
    Last Post: February 11th, 2011, 06:22 AM
  5. [SOLVED] how do I undo an AlphaComposite?
    By gib65 in forum AWT / Java Swing
    Replies: 3
    Last Post: October 21st, 2010, 04:23 PM