Ver Mensaje Individual
  #7 (permalink)  
Antiguo 01/11/2012, 21:46
Avatar de zero_master
zero_master
 
Fecha de Ingreso: junio-2011
Ubicación: Leon, Gto
Mensajes: 290
Antigüedad: 12 años, 10 meses
Puntos: 74
Respuesta: Veamos las coordenadas!!!

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 original
  1. import android.app.Activity;
  2. import android.os.Bundle;
  3. import android.graphics.Bitmap;
  4. import android.graphics.BitmapFactory;
  5. import android.widget.ImageView;
  6. import android.widget.LinearLayout;
  7. import android.widget.TextView;
  8. import android.view.MotionEvent;
  9. import android.view.View;
  10.  
  11. public class ImagRGBPixel extends Activity {
  12.     Bitmap bMap;
  13.     ImageView image;
  14.     TextView text,pixel;
  15.     /** Called when the activity is first created. */
  16.     @Override
  17.     public void onCreate(Bundle savedInstanceState) {
  18.         super.onCreate(savedInstanceState);
  19.         setContentView(R.layout.main);
  20.         LinearLayout MainLayout = (LinearLayout)findViewById(R.id.mainlayout);
  21.         bMap = BitmapFactory.decodeResource(getResources(), R.drawable.rgb);
  22.         image = (ImageView)findViewById(R.id.test_image);
  23.         text = (TextView)findViewById(R.id.RGB);
  24.         pixel = (TextView)findViewById(R.id.Pixel);
  25.         image.setImageBitmap(bMap);
  26.         image.setOnTouchListener(OnTouchListener);
  27.         MainLayout.setOnTouchListener(OnTouchListener1);
  28.     }
  29.     public int[] RGBreturn(int x)
  30.     {
  31.         int h[] = new int [4];
  32.         h[3] = (x>>24)&0xFF;
  33.         h[0] = (x>>16)&0xFF;
  34.         h[1] = (x>>8)&0xFF;
  35.         h[2] = x&0xFF;
  36.         return h;
  37.     }
  38.     private View.OnTouchListener OnTouchListener
  39.        = new View.OnTouchListener(){
  40.      
  41.      @Override
  42.      public boolean onTouch(View view, MotionEvent motionEvent) {
  43.       // TODO Auto-generated method stub
  44.       int x, y;
  45.       x = (int)motionEvent.getX();
  46.       y = (int)motionEvent.getY();
  47.       pixel.setText("Pixel: " + Integer.toString(x)+", "+ Integer.toString(y));
  48.       int pix = bMap.getPixel(x, y);
  49.       int h[] = RGBreturn(pix);
  50.       text.setText("A= "+Integer.toString(h[3])+" R= "+Integer.toString(h[0])+" G= "+Integer.toString(h[1])+" B= "+Integer.toString(h[2]));
  51.       return true; //means event have been processed
  52.      }
  53.        
  54.        };
  55.        private View.OnTouchListener OnTouchListener1
  56.        = new View.OnTouchListener(){
  57.      
  58.      @Override
  59.      public boolean onTouch(View view, MotionEvent motionEvent) {
  60.       // TODO Auto-generated method stub
  61.       pixel.setText("ERROR FUERA DE LA IMAGEN");
  62.       return true; //means event have been processed
  63.      }
  64.        
  65.        };
  66. }