1

私は Android の 2D グラフィックスが初めてで、これが可能かどうか知りたいと思っていました。

https://dl.dropbox.com/u/6818591/pendulum_background.png

上記のリンクの画像を使用して、指定した角度に基づいて特定の色で円の白い部分を塗りつぶし、黒い部分と透明な部分はそのままにしておきます。

メソッドを使用して弧を描くことdrawArc()ができましたが、画像を覆っています。この問題は、画像内の円弧が完全な円ではなく、わずかに押しつぶされているという事実によって複雑になります。

空白のみに描画する方法はありますか? フィルターやマスクを使用していますか? サンプルコードがあれば、それを使用できます。:)

ありがとう

4

2 に答える 2

3

これを試して

private Drawable fillBitmap(Bitmap bitimg1, int r, int g, int b) {
        Bitmap bitimg = bitimg1.copy(bitimg1.getConfig(), true);


    int a = transperentframe;
    Drawable dr = null;
    for (int x = 0; x < bitimg.getWidth(); x++) {
        for (int y = 0; y < bitimg.getHeight(); y++) {

            int pixelColor = bitimg.getPixel(x, y);
            int A = Color.alpha(pixelColor);
            bitimg.setPixel(x, y, Color.argb(A, r, g, b));
        }
    }
    Bitmap resizedBitmap = Bitmap.createScaledBitmap(bitimg,
            framewidth + 10, frameheight, true);

    dr = new BitmapDrawable(getResources(), resizedBitmap);

    return dr;
}

このコードを使用して、非透明領域に色を塗りつぶし、透明領域をそのまま残しました。

次のように確認することもできます。

if(canvasBitmap.getPixel(x, y) == Color.TRANSPARENT)

必要に応じて他の方法を適用して、任意の色 Color.BLUE を比較できます。

于 2013-11-26T17:53:16.937 に答える
1

ビットマップで使用canvas.drawPaint(..)して、特定の色を別の色で描画できます。

// make a mutable copy and a canvas from this mutable bitmap
Bitmap bitmap = bitmap.copy(Bitmap.Config.ARGB_8888, true);
Canvas canvas = new Canvas(bitmap);

// get the int for the colour which needs to be removed
Paint paint = new Paint();
paint.setARGB(255, 0, 0, 0); // ARGB for the color, in this example, white
int removeColor = paint.getColor(); // store this color's int for later use

// Next, set the color of the paint to the color another color            
paint.setARGB(/*put ARGB values for color you want to change to here*/);

// then, set the Xfermode of the pain to AvoidXfermode
// removeColor is the color that will be replaced with the paint color
// 0 is the tolerance (in this case, only the color to be removed is targetted)
// Mode.TARGET means pixels with color the same as removeColor are drawn on
paint.setXfermode(new AvoidXfermode(removeColor, 0, AvoidXfermode.Mode.TARGET));

// re-draw
canvas.drawPaint(p);
于 2013-03-15T22:16:24.930 に答える