2017-07-11 3 views
-1
imageView = (ImageView)findViewById(R.id.img); 
imageView.setImageResource(R.drawable.aa); 
// crash below into bitmap width and height > 0; 
bitmap = Bitmap.createBitmap(imageView.getWidth(),imageView.getHeight(), Bitmap.Config.ARGB_8888); 

canvas = new Canvas(bitmap); 
// imageView.setImageBitmap(bitmap); 
dw = imageView.getWidth(); 
dh = imageView.getHeight(); 

Log.e("bitmap", "bitmap" + imageView); 
Log.e("canvas", "canvas" + canvas); 
imageView.setOnTouchListener(this); 
//imageView.setOnClickListener(this); 
} 

public boolean onTouch(View v, MotionEvent event) { 

int action = event.getAction(); 
int x = (int) event.getX(); 
int y = (int) event.getY(); 

switch(action){ 
case MotionEvent.ACTION_DOWN: 
    if (x >= dh && x < (dh + bitmap.getWidth()) 
    && y >= dw && y < (dw + bitmap.getHeight())) { 
    } 
break; 
} 
return true; 
    } 
} 
+0

S'il vous plaît poser une bonne question – Ogbe

+0

-vous comprendre? –

+0

question n'est pas clair.Mettez-le et demandez correctement ce que vous voulez. – Rasel

Répondre

0

Remplacez le code par la ligne ci-dessous en cas de panne.

imageView.measure(0,0); 
bitmap = Bitmap.createBitmap(imageView.getMeasuredWidth(),imageView.getMeasuredHeight(), Bitmap.Config.ARGB_8888); 

aussi:

dw = imageView.getMeasuredWidth(); 
dh = imageView.getMeasuredHeight();