 |
Drag and Drop Effects and Java2D Performances
Posted by gfx on October 03, 2005 at 09:09 PM | Comments (5)
You can run the WebStart demo or download its source code.
Once the application is started, you can drag and drop pictures from the list on the left to the image viewer on the right and trigger a cool looking animation.
When writing this application, I found serious performances issues with J2SE 1.5. There were also some problems with Java SE 1.6 but far less important. Chris Campbell and Chet Haase really helped me on this. It turns out that loading an image with ImageIO does not necessarily provide a picture in a compatible format with the default screen configuration. When drawing such pictures you lose performances, especially when scaling them. An easy way to work around this problem is to convert them into compatible images:
public static BufferedImage loadCompatibleImage(URL resource) throws IOException {
BufferedImage image = ImageIO.read(resource);
GraphicsConfiguration configuration = GraphicsEnvironment.
getLocalGraphicsEnvironment().getDefaultScreenDevice().getDefaultConfiguration();
BufferedImage compatibleImage = configuration.createCompatibleImage(image.getWidth(),
image.getHeight());
Graphics g = compatibleImage.getGraphics();
g.drawImage(image, 0, 0, null);
g.dispose();
return compatibleImage;
}
I wrote a longer explanation you might want to check out if you need to perform heavy drawings with pictures in your application.
Bookmark blog post: del.icio.us Digg DZone Furl Reddit
Comments
Comments are listed in date ascending order (oldest first) | Post Comment
-
Hey Romain,
How are you? I have seen your works and I want to know if I can discuss some possible ideas with you. I am hoping these ideas may be incorporated into the Roller blog server project. I have a dream of turning Roller into a business model. I don't have the programming skills as you though but anyway send me an email at paksegu@yahoo.com.
Thanks -Ransford
http://www.rollerweblogger.org/page/project
Posted by: paksegu on October 03, 2005 at 10:18 PM
-
Hello Romain Sir,
my core interest in java technology only.
i read u'r blog and try out the code on my pc.
it was gr8, but couldn't figure out how u can think so complex things, currently i am working on project where i need to drag the image with text as well.
this might be helpful to me.
Posted by: yatinkumbhare on October 04, 2005 at 02:22 AM
-
This demo is very nice ! but very slow... and the opengl doesn't work with my ATI Card, mustang still did not correct this bug...
Posted by: loyl on October 05, 2005 at 11:52 AM
-
Hello there, I'm interested in learning drag and drop feature but unfortunately the examples in the sun java tutorial is too complicated for me to understand. I hope you can help me by telling m step by step how to create the drag and drop feature.
My main intention is to drag(copy) an icon from the left panel to the the right panel. I would like to be able to drop the icon exactly where my current cursor's position.
Posted by: dexterwong on January 03, 2007 at 06:22 AM
-
guaooooo!!! that's very nice! i have been looking for the way to drag and drop and image from a web page or a file into my application, but this is amazing in the way of it's look and the animation... how ever you are a genius if you have some idea that how can i do what i want to do, please send me a email... now I have to check this code.... but only one question why i couldn't see the rigth footer page turn over?
Posted by: gsmarty on March 22, 2007 at 09:25 PM
|