相关疑难解决方法(0)

如何在Android中获取像素颜色

我正在使用Intent来调用和显示来自Gallery的图像,现在我使它能够使用以下方法在TextView中获取图像的坐标:

final TextView textView = (TextView)findViewById(R.id.textView); 
final TextView textViewCol = (TextView)findViewById(R.id.textViewColor);
targetImage.setOnTouchListener(new ImageView.OnTouchListener(){     
    @Override   
    public boolean onTouch(View v, MotionEvent event) {
        // TODO Auto-generated method stub       
        int x=0;
        int y=0;
        textView.setText("Touch coordinates : " +       
        String.valueOf(event.getX()) + "x" + String.valueOf(event.getY()));
        ImageView imageView = ((ImageView)v);
        Bitmap bitmap = ((BitmapDrawable)imageView.getDrawable()).getBitmap();
        int pixel = bitmap.getPixel(x,y);
        int redValue = Color.red(pixel);
        int blueValue = Color.blue(pixel);
        int greenValue = Color.green(pixel);
        if(pixel == Color.RED){
               textViewCol.setText("It is RED");
            }

        /*if(redValue == 255){
            if(blueValue == 0)
                if(greenValue==0)
               textViewCol.setText("It is …
Run Code Online (Sandbox Code Playgroud)

android pixel

50
推荐指数
2
解决办法
9万
查看次数

OnPreviewFrame数据图像到imageView

我试图从相机的预览中获取byte [],将其转换为位图并使用imageView.setImageBitmap()在imageview上显示它

我已经设法开始预览并将其显示在surfaceView上,但我不知道如何在RGB位图中转换byte []数据(我认为是Yuv格式)以在imageView上显示它.

我正在尝试的代码如下:

camera = camera.open();
parameters = camera.getParameters();
camera.setParameters(parameters);
surfaceHolder = surfaceView.getHolder();
surfaceHolder.setType(SurfaceHolder.SURFACE_TYPE_PUSH_BUFFERS);
camera.setPreviewDisplay(surfaceHolder);
camera.setPreviewCallback(this);
camera.startPreview();
Run Code Online (Sandbox Code Playgroud)

并且预览回调就是这个

@Override
public void onPreviewFrame(byte[] data, Camera camera) {

    Camera.Parameters parameters = camera.getParameters();
    int width = parameters.getPreviewSize().width;
    int height = parameters.getPreviewSize().height;
    ByteArrayOutputStream outstr = new ByteArrayOutputStream();
    Rect rect = new Rect(0, 0, width, height); 
    YuvImage yuvimage=new YuvImage(data,ImageFormat.NV21,width,height,null);
    yuvimage.compressToJpeg(rect, 100, outstr);
    Bitmap bmp = BitmapFactory.decodeByteArray(outstr.toByteArray(), 0, outstr.size());
    imgView1.setImageBitmap(bmp);        
}
Run Code Online (Sandbox Code Playgroud)

预览有效但imageView仍为空

任何的想法?

android bitmap yuv android-camera

6
推荐指数
1
解决办法
2万
查看次数

获取android中imageview内的触摸位置

我的活动中有一个imageview,我可以通过onTouchListener获得用户触摸imageview的位置.我在用户触摸该图像的位置放置了另一个图像.我需要存储触摸位置(x,y),并在另一个活动中使用它来显示标签.我将触摸位置存储在第一个活动中.在第一个活动中,我的图像视图位于屏幕顶部.在第二个活动中它位于屏幕的底部.如果我使用从第一个活动中存储的位置,它会将标记图像放在顶部,而不是我之前在第一个活动中单击的imageview.无论如何都要在imageview中获得位置.

FirstActivity:

cp.setOnTouchListener(new OnTouchListener() {
        @Override
        public boolean onTouch(View v, MotionEvent event) {
            x = (int) event.getX();
            y = (int) event.getY();

            Log.v("touched x val of cap img >>", x + "");
            Log.v("touched y val of cap img >>", y + "");

            tag.setVisibility(View.VISIBLE);

            int[] viewCoords = new int[2];
            cp.getLocationOnScreen(viewCoords);

            int imageX = x - viewCoords[0]; // viewCoods[0] is the X coordinate
            int imageY = y - viewCoords[1]; // viewCoods[1] is the y coordinate
            Log.v("Real x >>>",imageX+"");
            Log.v("Real y >>>",imageY+"");

            RelativeLayout rl …
Run Code Online (Sandbox Code Playgroud)

android touch imageview

2
推荐指数
1
解决办法
3万
查看次数

标签 统计

android ×3

android-camera ×1

bitmap ×1

imageview ×1

pixel ×1

touch ×1

yuv ×1