DJ_AM_Juicebox
asked on
Graphics::drawImage() quality
Hi,
When i use the drawImage() function of Graphics, the output quality isn't that great. In win32, you can set some flags for interpolation type of the output image to the device context. Is there any parallel in java? I'd like to do a nicer interpolation than nearest neighbor (looks like that's what's being used)
Thanks
When i use the drawImage() function of Graphics, the output quality isn't that great. In win32, you can set some flags for interpolation type of the output image to the device context. Is there any parallel in java? I'd like to do a nicer interpolation than nearest neighbor (looks like that's what's being used)
Thanks
ASKER
Yeah that seems to be what im looking for, but how could I store those values to use later - I want to do something like:
Object m_ImageQuality = RenderingHints.VALUE_RENDE R_BILINEAR ;
// Later on
Graphics2D g2 = (Graphics2D)g;
RenderingHints hints = g2.getRenderingHints();
hints.put(RenderingHints.K EY_INTERPO LATION, m_ImageQuality);
g2.setRenderingHints(hints );
but Im getting exceptions relating to m_ImageQuality - what type is that supposed to be?
Thanks
Object m_ImageQuality = RenderingHints.VALUE_RENDE
// Later on
Graphics2D g2 = (Graphics2D)g;
RenderingHints hints = g2.getRenderingHints();
hints.put(RenderingHints.K
g2.setRenderingHints(hints
but Im getting exceptions relating to m_ImageQuality - what type is that supposed to be?
Thanks
whats the error?
ASKER
Exception getting thrown, says invalid argument for:
hints.put()
hints.put()
code looks fine, that method accepts 2 Objects
http://java.sun.com/javase/6/docs/api/java/awt/RenderingHints.html#put(java.lang.Object,%20java.lang.Object)
http://java.sun.com/javase/6/docs/api/java/awt/RenderingHints.html#put(java.lang.Object,%20java.lang.Object)
(I assume that your m_ImageQuality definition should be:
Object m_ImageQuality = RenderingHints.VALUE_INTER POLATION_B ILINEAR;
?)
Object m_ImageQuality = RenderingHints.VALUE_INTER
?)
Your code works fine for me. I wonder if it's your runtime (there's no guarantee that all of the algorithms are implemented). Try this, and let us know if the exception persists:
Object m_ImageQuality = RenderingHints.VALUE_RENDE R_DEFAULT ;
Object m_ImageQuality = RenderingHints.VALUE_RENDE
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
ah yeah im being dumb, VALUE_RENDER_DEFAULT had nothing to do with the interpolation schemes. I guess nearest neigbor is the default.
I think BILINEAR and BICUBIC are the same in my implementation, though I haven't examind the pixels programmatically. I'm surprised how slow it is.
Thanks!
I think BILINEAR and BICUBIC are the same in my implementation, though I haven't examind the pixels programmatically. I'm surprised how slow it is.
Thanks!
eg.
http://www.java2s.com/Code/JavaAPI/java.awt/Graphics2DsetRenderingHintsMaphints.htm