在我的应用程序中,我混合了2个位图,屏幕上有一个位图,当我用手指轻扫时,它会显示第二个位图的匹配像素。我现在的方式有效,但是当我触摸屏幕时,它只显示其他位图的正方形,因为像素是正方形,我通过触摸屏幕显示它们中的一组。 如何将像素组合在一起以创建圆圈?
这是我目前的代码:
@Override
public boolean onTouchEvent(MotionEvent event) {
super.onTouchEvent(event);
if (!surfaceReady)
return false;
// Check if the touch pointer is the one you want
if (event.getPointerId(event.getActionIndex()) == 0) {
switch (event.getAction()) {
case MotionEvent.ACTION_DOWN:
// User touched screen...
case MotionEvent.ACTION_MOVE:
// User dragged his finger...
blend((int) event.getX(), (int) event.getY());
}
// Update the blending effect bitmap here and trigger a frame
// redraw,
// if you don't already have an animation thread to do it for you.
drawOverlays();
return true;
}
return false;
}
混合代码:
// In order to make the effect more "visible" I've created a larger brush
public int BS = 50;
public int HBS = BS >> 1;
int[] pixels = new int[BS * BS];
private void blend(int x, int y) {
if (x >= HBS && y >= HBS && x < bmp2.getWidth() - HBS && x < operation.getWidth() - HBS && y < bmp2.getHeight() - HBS && y < operation.getHeight() - HBS) {
bmp2.getPixels(pixels, 0, BS, x - HBS, y - HBS, BS, BS);
operation.setPixels(pixels, 0, BS, x - HBS, y - HBS, BS, BS);
}
}