i want to get pixel value when i touch my screen. its in a class which extends a surfaceview
@Override
public boolean onTouchEvent(MotionEvent event) {
float x = event.getX();
float y = event.getY();
if(event.getAction()==MotionEvent.ACTION_MOVE)
{View v =this;
ImageView imageView = ((ImageView)v);
Bitmap bitmap = ((BitmapDrawable)imageView.getDrawable()).getBitmap();
int pixel = bitmap.getPixel((int)x,(int)y);
}
i am getting class cast exception error in
ImageView imageView = ((ImageView)v);
what i done wrong here. plz help
What is “this”, is it a reference to an ImageView ?
Which class is this code ? An Activity class ?
You need to provide more peace of code to we help you.
Probably “this” is an Activity context reference and you can’t cast it to an ImageView.
try it
where XXXX is your ImageView ID
Addition
You can do this if your surfaceView only has one ImageView on it. If you have more than one, you’ll probably need extra informations about it like it’s id/tag.