Results 1 to 3 of 3
  1. #1
    gogromat is offline Member
    Join Date
    Dec 2009
    Location
    Brooklyn, NY
    Posts
    3
    Rep Power
    0

    Red face BufferedImage clear off background

    Hello Everyone!

    I am working on the Java applet.
    I have an interesting question on how to clear off the background buffered image, because it doesn't allow to work my rotation function properly.
    When I hit the rotate button, the image rotates and translates, but I am able to see only the half of it, which overlaps the older bufferedimage :o

    Here is the code of my function:
    Java Code:
       
    if("Rotate".equals(e.getActionCommand())){
             Icon myIcon = label_image_edit.getIcon();
             BufferedImage bi = new BufferedImage(myIcon.getIconWidth(),myIcon.getIconHeight(),BufferedImage.TYPE_INT_RGB);
             myIcon.paintIcon(this,bi.createGraphics(),0,0);
             int h=bi.getWidth();
             int w=bi.getHeight();
             Graphics g = bi.getGraphics();
             Graphics2D g2=(Graphics2D)g; // Create a Java2D version of g.
             //------------------
    
    
    
    	//TRANSFORMATIONS
    	AffineTransform trans = new AffineTransform();
    	trans.translate(w+200,h-200);//Translate Image
    	trans.rotate(Math.toRadians(-180));//Rotate image 180 degrees
    
    
             //DRAWING
             g2.drawImage(bi, trans, null);//draw the Image
             ImageIcon ic_temp = new ImageIcon(bi);
             label_image_edit.setIcon(ic_temp);
             // g.dispose();
             // g2.dispose();
    }//end of if()
    Last edited by gogromat; 12-21-2009 at 12:36 AM.

  2. #2
    gogromat is offline Member
    Join Date
    Dec 2009
    Location
    Brooklyn, NY
    Posts
    3
    Rep Power
    0

    Default

    bump...Does anyone have an idea?
    Previously I had this code working with the older libraries on the Oracle,
    but it seems that now libraries have changed a lot, that's why I need
    some help on this...
    Last edited by gogromat; 12-21-2009 at 12:37 AM.

  3. #3
    gogromat is offline Member
    Join Date
    Dec 2009
    Location
    Brooklyn, NY
    Posts
    3
    Rep Power
    0

    Default

    Problem solved with additional AffineTransform:


    Java Code:
        if("Rotate".equals(e.getActionCommand())){
    		 Icon myIcon = label_image_edit.getIcon();
    		 Color transColor=new Color(0f,0f,0f,0f);
             BufferedImage bi = new BufferedImage(myIcon.getIconWidth(),myIcon.getIconHeight(),BufferedImage.TYPE_INT_RGB);
             myIcon.paintIcon(this,bi.createGraphics(),0,0);
    		 int h=bi.getWidth();
             int w=bi.getHeight();
             Graphics g = bi.getGraphics();
             Graphics2D g2=(Graphics2D)g; // Create a Java2D version of g.
    //------------------
    		 g2.setBackground(transColor);//make background black
    			 
    		 AffineTransform trans = new AffineTransform();
    		 trans.translate(w+200,h-200);//Translate Image
    		 trans.rotate(Math.toRadians(-180));//Rotate image 180 degrees
    
    		 //BufferedImage.clearBackground();
    		 clear();
    
    	      AffineTransformOp op = new AffineTransformOp(trans,AffineTransformOp.TYPE_BILINEAR);
              bi = op.filter(bi, null);
    
    		 
    		 g2.drawImage(bi, trans, null);//draw the Image
             ImageIcon ic_temp = new ImageIcon(bi);
             label_image_edit.setIcon(ic_temp);
    	}

Similar Threads

  1. Using BufferedImage
    By timkd127 in forum New To Java
    Replies: 5
    Last Post: 12-19-2009, 10:17 PM
  2. BufferedImage imageScaling
    By MINGxDOG in forum New To Java
    Replies: 2
    Last Post: 11-17-2009, 04:04 PM
  3. BufferedImage through FTP
    By dudejonne in forum New To Java
    Replies: 7
    Last Post: 11-05-2009, 06:36 PM
  4. Converting BufferedImage Into ImageIcon
    By hitmen in forum AWT / Swing
    Replies: 9
    Last Post: 03-25-2009, 09:10 AM
  5. BufferedImage to Byte
    By Java Tip in forum Java Tip
    Replies: 0
    Last Post: 01-22-2008, 09:17 PM

Posting Permissions

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