2010-04-21 96 views
1

我要裁剪图像的一部分,对于我使用以下代码:黑莓 - 裁剪图像

int x=20; 
    int y=50; 
    int [] rgbdata=new int[(0+width-x+height-y)* (image.getWidth())]; 
    image.getARGB(rgbdata, 0, image.getWidth(), x, y, width, height); 
    cropedImage=new Bitmap(image.getWidth(),image.getWidth()); 
    cropedImage.setARGB(rgbdata, 0,image.getWidth(), 80,80, width, height); 

x上的y是从哪里裁剪将在矩形形状来完成的位置。 但它无法工作,请任何人帮助我。任何示例代码都适用于我。 其紧急。 由于事先

回答

3

,你可以做到这一点使用的图形:

public Bitmap cropImage(Bitmap image, int x, int y, int width, int height) { 
    Bitmap result = new Bitmap(width, height); 
    Graphics g = new Graphics(result); 
    g.drawBitmap(0, 0, width, height, image, x, y); 
    return result; 
}