Results 1 to 3 of 3
- 12-20-2009, 05:31 PM #1
Member
- Join Date
- Dec 2009
- Location
- Brooklyn, NY
- Posts
- 3
- Rep Power
- 0
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-20-2009 at 11:36 PM.
- 12-20-2009, 11:34 PM #2
Member
- Join Date
- Dec 2009
- Location
- Brooklyn, NY
- Posts
- 3
- Rep Power
- 0
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-20-2009 at 11:37 PM.
- 12-21-2009, 01:17 AM #3
Member
- Join Date
- Dec 2009
- Location
- Brooklyn, NY
- Posts
- 3
- Rep Power
- 0
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
-
Using BufferedImage
By timkd127 in forum New To JavaReplies: 5Last Post: 12-19-2009, 09:17 PM -
BufferedImage imageScaling
By MINGxDOG in forum New To JavaReplies: 2Last Post: 11-17-2009, 03:04 PM -
BufferedImage through FTP
By dudejonne in forum New To JavaReplies: 7Last Post: 11-05-2009, 05:36 PM -
Converting BufferedImage Into ImageIcon
By hitmen in forum AWT / SwingReplies: 9Last Post: 03-25-2009, 08:10 AM -
BufferedImage to Byte
By Java Tip in forum Java TipReplies: 0Last Post: 01-22-2008, 08:17 PM


LinkBack URL
About LinkBacks
Reply With Quote
Bookmarks