deep inside java

M

Margus

Hi
At moment i'm searching solution for scaling chart picture in java without
loss. The speed in scrolling with lightweights seems ok. But problem is with
drawimage() the chart line gets fragmented if scaling with this function. I
use the direct 8 parameter version of drawimage. Any techniques or solution
to get over it.

If anybody has some reading or material about drawing and awt components in
lowlevel java and he can share it - it would be very big help.

Best Regards
Margus
 
R

Roedy Green

At moment i'm searching solution for scaling chart picture in java without
loss. The speed in scrolling with lightweights seems ok. But problem is with
drawimage() the chart line gets fragmented if scaling with this function. I
use the direct 8 parameter version of drawimage. Any techniques or solution
to get over it.

Check out http://mindprod.com/jgloss/java2d.html
 
M

Margus

Hi again

Well when this function resizes chart(making it smaller) . Some part of the
chart line will not be visible anymore this is because the function
automatically calculates the picture and scales it and the 1 pixel width
line will not be visible anymore. Any ways to get around from this.

I hope i explained it now more. Loss is really not very accurate :)

Margus
 
H

hondacivic

Margus said:
automatically calculates the picture and scales it and the 1 pixel width
line will not be visible anymore. Any ways to get around from this.

Not sure if this is what you mean: scaling a bitmap seems to drop
pixels completely.

This is what the default 'nearest neighbor' scaling algorithm does.
It's the fastest and simplest way of scaling a bitmap. It drops one
or more every one or more pixels.
Java has at least 2 other scaling algorithms as well: linear, and
bicubic.
In linear, what it does is for each pixel in the resulting bitmap, it
checks to see how much of the 4 pixels in the source it should sample
from. Not perfect, but a lot better than nearest neighbor, and still
pretty fast.
Bicubic is way better, but a little slower, although Java's
implementation has been optimized pretty darn well. What it does for
each pixel, which area of pixels from the source should influence the
outcome pixel. This means that if you scale a bitmap down a lot, for
each pixel in the resulting bitmap, it needs to scan a larger number
of pixels in the source bitmap, and calculate by weighted average each
resulting pixel.

What you should look at is in the paint(Graphics g), cast the g into a
Graphics2D, and call setRenderingHints on it.
You'll want to at least enable antialiasing, but probably also a few
other ones.
The quality goes way up for all sorts of things. Fonts, etc, it'll
all look a 1.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,755
Messages
2,569,537
Members
45,020
Latest member
GenesisGai

Latest Threads

Top