2017-03-09 9 views
0

の残りの部分を描くアンドロイド私はそうあなたが助けてくださいfar.Couldことを達成するためのビットマップから四角形をトリミングしcanvas.Could上の画像の残りの部分を描画しようとしていますか?コードは、コード -Javaは矩形を削除し、画像

Bitmap bitmap = Bitmap.createBitmap(view.getWidth(), view.getHeight(), ARGB_8888);   
    Canvas canvas = new Canvas(bitmap); 
    Paint p = new Paint(); 
    p.setXfermode(new PorterDuffXfermode(PorterDuff.Mode.DARKEN)); 
    activity.getWindow().getDecorView().draw(canvas); 
    canvas.drawRect(rect,p); 
    canvas.save(); 

以下手動矩形座標又は供給イメージを計算することができ、我々が使用できるアクティビティのビットマップから矩形部分を除去するためにbelow-

1. //draw activity on the canvas. this returns a bitmap used in Bitmap.createBitmap(3) 
activity.getWindow().getDecorView().draw(canvas); 

2. //get the coordinates that I want to clip. 
Rect removeImage = new rect(coordinates of rect portion) 

3. //check that I can get the cropped image 
Bitmap croppedImage = Bitmap.createBitmap(bitmap, leftCrop, topCrop, rightCrop, bottomCrop); 

4. //Now I want to get the remaining canvas and remove the rectangular region 
????????? 
+0

その 'createBitmap(ビットマップソース、 INT X、 INT yを、 INT幅、 INT高さ)'はなく 'createBitmap(ビットマップをソース、 int型は、x、int型 yを、 int型の右、 int型の下部) '、また、あなたは' ' "私は残りのキャンバスを取得したい" とはどういう意味ですか?私は私がしたいことは維持することであるとして、ここで、(長方形がxで始まる、yは幅と高さを持つ私が指定)createBitmap(ビットマップソース、int型のx、int型のy、int型の幅、int型の高さが)私にトリミングされた画像を与えることだった何を意味するのか – pskink

+0

残りの画像はここに示すようにhttp://www.screencast.com/t/iZlJ0cCDrIH – Galileo123

+0

です。キャンバスAPIを使用してオリジナルのビットマップから任意の領域を削除/クリアします – pskink

答えて

0

通りです。 Iビューを通過し、次の使用 -

Rect coordinates = new Rect(); 
    int[] xyLocation = new int[2]; 
    if (view == null) { 
     return coordinates; 
    } 
    view.getLocationOnScreen(xyLocation); 
    coordinates.left = xyLocation[0]; 
    coordinates.top = xyLocation[1]; 
    coordinates.right = coordinates.left + view.getWidth(); 
    coordinates.bottom = corrdinates.top + view.getHeight(); 
    return coordinates; 

removed rectangle from activity screen shot

関連する問題