NetBeans 6 delivers great updates to the Matisse GUI builder. Spend a few minutes with Roman Strobl and get an expert briefing on what's new and what has changed. (sponsored)
In this, the third and final installation of Andres' Introduction to Groovy series, you learn about how Groovy handles variable numbers of arguments, named parameters, currying, and more about Groovy operators. Including, some new operators.
Swing Fuse (actually just Fuse), is a framework designed to make it easier to create your own custom desktop components. In this article, Daniel Spiewak shows you how to get started and provides sample source code you can download.
Willam Louth shows how he uses JXInsight Probes to investigate probable performance issues with code bases that he is not familiar with. He also highlights possible pitfalls in creating a benchmark, as well as in the analysis of results.
Replies:
24 -
Pages:
2
[
12
| Next
]
Threads:
[
Previous
|
Next
]
Images are the staple of any graphical application, whether on the web or on the desk, images are everywhere. Having the ability to control and manipulate these images is a crucial skill that is absolutely necessary for any graphical artist, designer, or Game Engineer. This article will get you, the aspiring artist, professional designer, or amateur hobbyist, the foundations to be able to manipulate any image to your will.
One thing that is strange. My color picker (
Colorspace
) reports that the green in the Mario tile is #008500 in Firefox but #007300 when I paint the same image in Java 2D or open the file in Photoshop.
Nice article, although it doesn't cover painting with Graphics2D in an orderly fashion, namely in the paintComponent method.
You don't call drawImage outside the event thread.
There is no guarantee whatsoever that anything will be drawn.
The correct time to draw something on the screen is when paintComponent is called, taking into account any clipping rectangle.
Also, I wouldn't dream on using ResizeListener to redraw. AWT handles this part quite nicely.
Those are quite necessary to get a better understanding of Java images. More importantly, those articles shed the light on some performance issues you may encounter. Be sure to read about the managed images.
Definitely check out the resources that Romain pointed to, especially Chris's article on why getScaledInstance() is horribly slow (and what better alternatives exist).
I would also point out that at a minimum, you should set the rendering hint to scale using Bilinear filtering when using the drawImage() call. This will give you much better quality than the default scale, at reasonable performance (nowhere near the hit of getScaledInstance()).
This will result in a decent-quality scale when down-scaling to an image that's greater than half the size of the original image. When downscaling by a larger factor, you'll want to use the approach outlined in Chris's article.
Quite a lot of bad advice here, especially for drawing images on frames. Getting the Graphics of the root pane directly is *not* how it should be done. Of course you will have problems on resizing the frame - you're not doing the painting in paintComponent. You will also have problems on hiding and reshowing the frame.
The solution is not to add resize listeners. The solution is to load the image and add a panel to the frame. The panel will override the paintComponent method and paint the image using the passed graphics. This will provide complete support for resizing, reshowing and double buffering.
Hopefully this article will be corrected so it won't mislead future Google referees.
You're right, I was merely demonstrating a way to display the images. The point was to give them image functions and let the reader apply them, wrapped in their own applications. But I see your point, so I will update the article to use a sub-class of JPanel to put the image in. That will solve the resizing, buffering and threading problems I hope.
Main thing is that many of the intended audience will simply copy-paste the code they find on the Internet, so you should be very careful in writing code under such a title a "Ultimate Java Image Manipulation".
Ultimate Java Image Manipulation
URL: Javalobby
At 4:00 AM on Sep 17, 2007, Michael Urban wrote:
Fresh Jobs for Developers Post a job opportunity
Read the full article here.
24 replies so far (
Post your own)
0x007300
Wow.. written by a high school senior. The mask and sprite code is really cool. So I made a Javascript "mashup" in Darkstar FX .One thing that is strange. My color picker ( Colorspace ) reports that the green in the Mario tile is #008500 in Firefox but #007300 when I paint the same image in Java 2D or open the file in Photoshop.
Re: 0x007300
> Wow.. written by a high school senior.Amazing, isn't it! Josiah did a fabulous job, and I hope we'll see more like this from him. This is great stuff!
Rick
bestuff.com - the best stuff in the world
Re: 0x007300
Yes, that's a great article - thanks. The author obviously knows his stuff!!As someone who normally lives in the EE arena, its good to read about desktop Java and how things like graphics manipulation are achieved.
Re: Ultimate Image Manipulation
Nice article, although it doesn't cover painting with Graphics2D in an orderly fashion, namely in the paintComponent method.You don't call drawImage outside the event thread.
There is no guarantee whatsoever that anything will be drawn.
The correct time to draw something on the screen is when paintComponent is called, taking into account any clipping rectangle.
Also, I wouldn't dream on using ResizeListener to redraw. AWT handles this part quite nicely.
Re: Ultimate Java Image Manipulation
Nice article. However, if you need more information about resizing images, take a look at Chris Campbell's article: http://today.java.net/pub/a/today/2007/04/03/perils-of-image-getscaledinstance.htmlIt explains in great details why getScaledInstance() is a lot slower than the method described by Josiah.
Also, flipping can be achieved by using the Graphics2D.scale() method, similarly to how rotation is done. It might be a bit easier to read.
I also HIGHLY recommend reading Chet's article on BufferedImages:
http://weblogs.java.net/blog/chet/archive/2004/08/toolkitbuffered.html
http://weblogs.java.net/blog/chet/archive/2003/08/bufferedimage_a.html
http://weblogs.java.net/blog/chet/archive/2003/08/bufferedimage_a_1.html
http://weblogs.java.net/blog/chet/archive/2003/09/volatileimage_n.html
Those are quite necessary to get a better understanding of Java images. More importantly, those articles shed the light on some performance issues you may encounter. Be sure to read about the managed images.
Romain Guy's Java Weblog, #ProgX, Jext
Re: Ultimate Java Image Manipulation
You can also read the Chapter 8 of Filthy Rich Client while waiting for the book to arrivehttp://www.informit.com/articles/article.aspx?p=1013851&rl=1
JLearnIt, Ant Commander, XINS, japplis.com.
Re: Ultimate Java Image Manipulation
You can also do thatRomain Guy's Java Weblog, #ProgX, Jext
Re: Ultimate Java Image Manipulation
Definitely check out the resources that Romain pointed to, especially Chris's article on why getScaledInstance() is horribly slow (and what better alternatives exist).I would also point out that at a minimum, you should set the rendering hint to scale using Bilinear filtering when using the drawImage() call. This will give you much better quality than the default scale, at reasonable performance (nowhere near the hit of getScaledInstance()).
So where the article has this code:
I would recommend this instead:
This will result in a decent-quality scale when down-scaling to an image that's greater than half the size of the original image. When downscaling by a larger factor, you'll want to use the approach outlined in Chris's article.
Chet.
Re: Ultimate Java Image Manipulation
Quite a lot of bad advice here, especially for drawing images on frames. Getting the Graphics of the root pane directly is *not* how it should be done. Of course you will have problems on resizing the frame - you're not doing the painting in paintComponent. You will also have problems on hiding and reshowing the frame.The solution is not to add resize listeners. The solution is to load the image and add a panel to the frame. The panel will override the paintComponent method and paint the image using the passed graphics. This will provide complete support for resizing, reshowing and double buffering.
Hopefully this article will be corrected so it won't mislead future Google referees.
Kirill
Re: Ultimate Java Image Manipulation
ChetThat makes sense, thanks, Ill add that in.
I read some of your articles by the way, their really great, and informative.
-Josiah
Re: Ultimate Java Image Manipulation
You're right, I was merely demonstrating a way to display the images. The point was to give them image functions and let the reader apply them, wrapped in their own applications. But I see your point, so I will update the article to use a sub-class of JPanel to put the image in. That will solve the resizing, buffering and threading problems I hope.Thanks for your help!
-Josiah
Re: Ultimate Java Image Manipulation
Thanks, JosiahMain thing is that many of the intended audience will simply copy-paste the code they find on the Internet, so you should be very careful in writing code under such a title a "Ultimate Java Image Manipulation".
Looking forward to seeing next articles.
Kirill
Re: Ultimate Java Image Manipulation
> Main thing is that many of the intended audience will simply copy-paste the code they find on the Internet,Which is why I always sneak in some code that sends money to my paypal account in all sample code I publish! =)
Dmitri
Re: Ultimate Java Image Manipulation
Unfortunately an exception is thrown loading image coded in CMYK colorspace (javax.imageio.IIOException - Unsupported Image Type). Anyone knows workaround for this?