0
私はチェスアプリをやっています。ボードのタイルを描くと、(透明な)背景に色付けされません。基本的に私が望むのは、ImageViewで、背景色が透明な画像(透明な背景)を表示する場合と同様です。私はdrawBitmap call
前に、これらの2行をコメントアウトした場合、私が手色付きの背景を持つキャンバスにビットマップを描画します。
これは、コード
private final Paint squareColor;
private Rect tileRect;
private Drawable pieceDrawable;
public Tile(final int col, final int row) {
this.col = col;
this.row = row;
this.squareColor = new Paint();
squareColor.setColor(isDark() ? Color.RED : Color.WHITE);
}
public void draw(final Canvas canvas) {
if(pieceDrawable != null) {
Bitmap image = ((BitmapDrawable) pieceDrawable).getBitmap();
ColorFilter filter = new LightingColorFilter(squareColor.getColor(), Color.TRANSPARENT);
squareColor.setColorFilter(filter);
canvas.drawBitmap(image, null, tileRect, squareColor);
} else {
canvas.drawRect(tileRect, squareColor);
}
}
であり、これはチェス盤(左画像)のように見える方法です
右側の画像としてボード。
ColorFilter filter = new LightingColorFilter(squareColor.getColor(), Color.TRANSPARENT);
squareColor.setColorFilter(filter);
私の作品は、ピースが、正方形で描かれていない透明な背景を持つ通常のイメージです。私はどのようにしての背後にある赤の色をにすることができますか? (同じイメージを背景色またはカラー表示にしたImageViewの場合と同じように)
Works!どうもありがとう。将来的に、タイルの色をドロウアブル/ビットマップに置き換えたい場合には、どうすればよいのでしょうか? (木製のイメージ/マスクなど) – BlackBox
'drawRect()'呼び出しを 'drawBitmap()'で置き換えるだけです。 'Canvas'では、' draw'呼び出しがもう一方の上に描画されます。 –