Hi,
I have a png wrapped in an Image object. I can draw it to screen like:
public void draw(Graphics g)
{
g.drawImage(img, 0, 0, Graphics.TOP | Graphics.LEFT);
}
Now the image is 128 x 160 pixels.
Is there a way I can get drawImage() to only draw128 x 128 pixels? I was hoping there'd be an overloaded method in drawImage() like:
drawImage(Image, x, y, widthToDraw, heightToDraw);
but no luck.
Is there some other way to crop the image? I'm thinking I can do something like:
img.getRGB(rgbData, offset, scanlength, x, y, width, height);
g.drawRGB(rgbData, offset, scanLength, x, y, width, height, processAlpha);
So I'd extract only 128 pixels vertically into a temporary rgb buffer, then use that with g.drawRGB() ?
Thanks
by: rrz@871311Posted on 2008-06-05 at 10:14:06ID: 21721777
I don't have time to test my idea right now. But I think you should look at son.com/si te/global/ techsuppor t/ tipstric kscode/jav a/p_java_0 502.jsp
http://developer.sonyerics
So, yes use img.getRGB . That will get you a int[] .
But you want to use Image method
createImage(byte[] imageData, int imageOffset, int imageLength)
which requires a byte[]
So use code in link to convert.