Image stretch

I googled a lot, but I couldn’t it :-.

I need to draw my image into a Graphics2D using linear interpolation:
I need something like:


myGraphics2d.stretchImage(myImage,0,0,myImage.getWidth()*2,myImage.getHeight()*2);

There’s a drawImage() method, but it doesn’t stretch the image using linear interpolation.

http://java.sun.com/j2se/1.5.0/docs/api/java/awt/Image.html#getScaledInstance(int,%20int,%20int)

But its pretty slow. So, only use it as part of the loading sequence.

The other options are the ddscale flag (OS/driver dependant behavior) or opengl (either lwjgl or jogl).

It creates a new image object :-?.

Is there a way to draw an scaled image directly on the graphics?

Look up:

Graphics2D.setRenderingHints(Map hints)
and
RenderingHints.VALUE_INTERPOLATION_BILINEAR

Please forget about getScaledInstance(), it’s an old and slow api.
If you need to create a scaled copy, just create a new image with the right dimensions and copy/scale the source
image into it.

For scaling on the fly you can use one of Graphics.drawImage() variants which takes the dimensions of the destination.

There’s a way to scale your image to the destination rectangle, or any rect. region of the source
image to any rect. region of the destination image.

Thanks,
Dmitri