public static Image getAdjustedImage(Image image, int _width, int _height)
{
int srcWidth = image.getWidth();
int srcHeight = image.getHeight();
Image tmp = Image.createImage(_width, srcHeight);
Graphics g = tmp.getGraphics();
int ratio = (srcWidth << 16) / _height;
int pos = ratio/2;
//Horizontal Resize
for (int x = 0; x < _width; x++)
{
g.setClip(x, 0, 1, srcHeight);
g.drawImage(image, x - (pos >> 16), 0, Graphics.LEFT | Graphics.TOP);
pos += ratio;
}
Image resizedImage = Image.createImage(_width, _height);
g = resizedImage.getGraphics();
ratio = (srcHeight << 16) / _height;
pos = ratio/2;
//Vertical resize
for (int y = 0; y < _height; y++)
{
g.setClip(0, y, _width, 1);
g.drawImage(tmp, 0, y - (pos >> 16), Graphics.LEFT | Graphics.TOP);
pos += ratio;
}
return resizedImage;
}