Saludos encontre entre mis archivos otro proyecto que hice... hago lo mismo pero le aplico el OnTouch a un ImageView para ver los valores de los pixeles en una imagen... espero te sirva
Código Javascript
:
Ver originalimport android.app.Activity;
import android.os.Bundle;
import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.TextView;
import android.view.MotionEvent;
import android.view.View;
public class ImagRGBPixel extends Activity {
Bitmap bMap;
ImageView image;
TextView text,pixel;
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
LinearLayout MainLayout = (LinearLayout)findViewById(R.id.mainlayout);
bMap = BitmapFactory.decodeResource(getResources(), R.drawable.rgb);
image = (ImageView)findViewById(R.id.test_image);
text = (TextView)findViewById(R.id.RGB);
pixel = (TextView)findViewById(R.id.Pixel);
image.setImageBitmap(bMap);
image.setOnTouchListener(OnTouchListener);
MainLayout.setOnTouchListener(OnTouchListener1);
}
public int[] RGBreturn(int x)
{
int h[] = new int [4];
h[3] = (x>>24)&0xFF;
h[0] = (x>>16)&0xFF;
h[1] = (x>>8)&0xFF;
h[2] = x&0xFF;
return h;
}
private View.OnTouchListener OnTouchListener
= new View.OnTouchListener(){
@Override
public boolean onTouch(View view, MotionEvent motionEvent) {
// TODO Auto-generated method stub
int x, y;
x = (int)motionEvent.getX();
y = (int)motionEvent.getY();
pixel.setText("Pixel: " + Integer.toString(x)+", "+ Integer.toString(y));
int pix = bMap.getPixel(x, y);
int h[] = RGBreturn(pix);
text.setText("A= "+Integer.toString(h[3])+" R= "+Integer.toString(h[0])+" G= "+Integer.toString(h[1])+" B= "+Integer.toString(h[2]));
return true; //means event have been processed
}
};
private View.OnTouchListener OnTouchListener1
= new View.OnTouchListener(){
@Override
public boolean onTouch(View view, MotionEvent motionEvent) {
// TODO Auto-generated method stub
pixel.setText("ERROR FUERA DE LA IMAGEN");
return true; //means event have been processed
}
};
}