私はFinger Paintsアプリケーションで2つのビットマップを比較するために何かしようとしました。私は最初に2d配列に最初のビットマップをロードし、次に別の配列にフィンガーペイントから他の出力ビットマップをロードし、両方のビットマップを比較したいと思います。私のコードはうまくいかず、どこで編集するべきか分かりません。比較機能は、オプションメニューの「比較」オプションを押した直後に開始されます。私を助けてください。フィンガーペイントの使用方法比較機能を有効にする方法は?
public class MainActivity extends GraphicsActivity
{
boolean check = false;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(new MyView(this));
mPaint = new Paint();
mPaint.setAntiAlias(true);
mPaint.setDither(true);
mPaint.setColor(Color.RED);
mPaint.setStyle(Paint.Style.STROKE);
mPaint.setStrokeJoin(Paint.Join.ROUND);
mPaint.setStrokeCap(Paint.Cap.ROUND);
mPaint.setStrokeWidth(20);
}
private Paint mPaint;
public class MyView extends View {
Bitmap mBitmap;
Bitmap bitmap = BitmapFactory.decodeResource(getResources(), R.drawable.c_1);
Bitmap bitmap2;
private Canvas mCanvas;
private Path mPath;
private Paint mBitmapPaint;
int w1 = bitmap.getWidth();
int h1 = bitmap.getHeight();
int [][] array = new int [w1][h1];
int b=0;
int c=0;
int k=0;
int i, j;
int l=0;
View content = this;
{
for(int j = 0;j< w1; j++){
for(int i = 0;i< h1; i++,k++){
array[j][i]= bitmap.getPixel(j, i);
if(bitmap.getPixel(j, i)== 100);
{
b++;
}
}
}
System.out.println("numbers of gray:" + b);
}
public MyView(Context c) {
super(c);
mPath = new Path();
mBitmapPaint = new Paint(Paint.DITHER_FLAG);
content.setDrawingCacheEnabled(true);
content.setDrawingCacheQuality(View.DRAWING_CACHE_QUALITY_HIGH);
}
@Override
public void onSizeChanged(int w, int h, int oldw, int oldh){
super.onSizeChanged(w, h, oldw, oldh);
mBitmap = Bitmap.createBitmap(w, h, Bitmap.Config.ARGB_8888);
mCanvas = new Canvas(mBitmap);
}
@Override
protected void onDraw(Canvas canvas) {
canvas.drawColor(Color.WHITE);
canvas.drawBitmap(bitmap, 0, 0, null);
canvas.drawBitmap(mBitmap, 0, 0, mBitmapPaint);
canvas.drawPath(mPath, mPaint);
bitmap2 = content.getDrawingCache();
}
private float mX, mY;
private static final float TOUCH_TOLERANCE = 4;
private void touch_start(float x, float y) {
mPath.reset();
mPath.moveTo(x, y);
mX = x;
mY = y;
}
private void touch_move(float x, float y) {
float dx = Math.abs(x - mX);
float dy = Math.abs(y - mY);
if (dx >= TOUCH_TOLERANCE || dy >= TOUCH_TOLERANCE) {
mPath.quadTo(mX, mY, (x + mX)/2, (y + mY)/2);
mX = x;
mY = y;
}
}
private void touch_up() {
mPath.lineTo(mX, mY);
mCanvas.drawPath(mPath, mPaint);
mPath.reset();
}
@Override
public boolean onTouchEvent(MotionEvent event) {
float x = event.getX();
float y = event.getY();
System.out.println("Coordinates:" + x + "," + y);
switch (event.getAction()) {
case MotionEvent.ACTION_DOWN:
touch_start(x, y);
invalidate();
break;
case MotionEvent.ACTION_MOVE:
touch_move(x, y);
invalidate();
break;
case MotionEvent.ACTION_UP:
touch_up();
invalidate();
break;
}
return true;
}
private void compare(Boolean check){
if(check == true)
{
int w2 = bitmap2.getWidth();
int h2 = bitmap2.getHeight();
System.out.println("Width and Height of the product:" + w2 + "," + h2);
int [][] array1 = new int [w2][h2];
{
for(int j1 = 0;j1< w2; j1++){
for(int i1 = 0;i1< h2; i1++,l++){
array1[j1][i1]= bitmap2.getPixel(j1, i1);
if(array[j1][i1]== 100 && array1[j1][i1] == Color.RED);
{
c++;
}
}
}
System.out.println("numbers pixels touched:" + c);
}
int d=(b-c)/b*100;
Toast t = Toast.makeText(getBaseContext(), "Completion :" + d + "%", Toast.LENGTH_SHORT);
t.show();
}
}
}
private static final int CLEAR_MENU_ID = Menu.FIRST;
private static final int COMPARE_ID = Menu.FIRST + 1;
public boolean onCreateOptionsMenu(Menu menu) {
super.onCreateOptionsMenu(menu);
menu.add(0, CLEAR_MENU_ID, 0, "Clear ALL");
menu.add(0, COMPARE_ID, 0, "Compare");
return true;
}
@Override
public boolean onOptionsItemSelected(MenuItem item) {
switch (item.getItemId()) {
case CLEAR_MENU_ID:
setContentView(new MyView(this));
check = false;
return true;
case COMPARE_ID:
check = true;
return true;
}
return super.onOptionsItemSelected(item);
}
}
「私のコードは機能しません」という意味は?何がうまくいかない? – Simon
私は "比較"オプションを押しても、何も起こらない。 – Soo