【问题标题】:i need to access images from gallery and then access the pixels of the image for further processing in android我需要从图库中访问图像,然后访问图像的像素以在 android 中进行进一步处理
【发布时间】:2014-03-14 12:29:50
【问题描述】:

这是我目前正在使用的代码,该代码仅显示图库中的图像。但我想访问图像的像素。我很困惑图像数据在代码中存储在哪个变量中。

 @Override
  public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.main);

    Button buttonLoadImage = (Button) findViewById(R.id.buttonLoadPicture);
    buttonLoadImage.setOnClickListener(new View.OnClickListener() {

        @Override
        public void onClick(View arg0) {

            Intent i = new Intent(
                    Intent.ACTION_PICK,
                    android.provider.MediaStore.Images.Media.EXTERNAL_CONTENT_URI);

            startActivityForResult(i, RESULT_LOAD_IMAGE);
        }
    });
}


@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
    super.onActivityResult(requestCode, resultCode, data);

    if (requestCode == RESULT_LOAD_IMAGE && resultCode == RESULT_OK && null != data) {
        Uri selectedImage = data.getData();
        String[] filePathColumn = { MediaStore.Images.Media.DATA };

        Cursor cursor = getContentResolver().query(selectedImage,
                filePathColumn, null, null, null);
        cursor.moveToFirst();

        int columnIndex = cursor.getColumnIndex(filePathColumn[0]);
        String picturePath = cursor.getString(columnIndex);
        cursor.close();

        ImageView imageView = (ImageView) findViewById(R.id.imgView);
        imageView.setImageBitmap(BitmapFactory.decodeFile(picturePath));

    }


  }
}

【问题讨论】:

  • 你想用“像素”做什么

标签: android image android-image android-gallery


【解决方案1】:

请参考这个Answer on SO,这里描述获取Pixels,你应该使用:

Bitmap bm = BitmapFactory.decodeFile(picturePath);

然后:

bm.getPixel(x,y);// will return an int that corresponds to an int in the Color class, such as Color.BLACK or Color.WHITE.

希望对你有帮助

【讨论】:

    猜你喜欢
    • 2011-09-13
    • 2012-05-10
    • 2013-05-21
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2018-07-05
    • 1970-01-01
    相关资源
    最近更新 更多