/**
* Rescales the image to a specified width
* The new height is chosen to preserve the aspect ratio
*
* @param newWidth is the new width of the image
*/
public void rescaleToWidth(int newWidth)
{
int newHeight;
newHeight = (image.getHeight() * newWidth) / image.getWidth();
rescale(newWidth, newHeight);
}
/**
* Rescales the image to a specified width and height
*
* @param newWidth is the new width of the image
* @param newHeight is the new height of the image
*/
public void rescale(int newWidth, int newHeight)
{
int rgb[];
int rescaledRGB[];
int width, height;
// Current width and height values
width = image.getWidth();
height = image.getHeight();
// Get the RGB values for each pixel in the image
rgb = new int[ width * height ];
image.getRGB( rgb, 0, width, 0, 0, width, height );
// Create a new rescaled image
rescaledRGB = reescaleArray( rgb, width, height, newWidth, newHeight );
image = Image.createRGBImage( rescaledRGB, newWidth, newHeight, true );
}
--------------------------------------------------------------------
I use the code in the paint method of my splash screen:
Picture logo = new Picture();
logo.setImage("/logo.png");
logo.rescaleToWidth(g.getClipWidth() -
UIManager.getTheme().getVerticalScrollbarWidth() - 1);
Original issue reported on code.google.com by deanbro...@gmail.com on 10 Jul 2008 at 5:12
Original issue reported on code.google.com by
deanbro...@gmail.com
on 10 Jul 2008 at 5:12