简体   繁体   中英

How to get image id from uri?

I have this code:

@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
    super.onActivityResult(requestCode, resultCode, data);
    Button play= (Button) findViewById(R.id.play);
    play.setVisibility(1);
    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));
    }
}
public void Play(View view){
    int[] mImageIds = {R.id.imgView};
    Intent intent = new Intent(this, PuzzleSelectActivity.class);
    intent.putExtra("images", mImageIds);
    this.startActivity(intent);
}

i want to get the image id from the protected void onActivityResult and pass it on the mImageIds...

 protected void onActivityResult(int requestCode, int resultCode, Intent data)
 {
   super.onActivityResult(requestCode, resultCode, data);
   if (resultCode == RESULT_OK)
    {
    Uri imageUri = data.getData();
    Bitmap bitmap = MediaStore.Images.Media.getBitmap(this.getContentResolver(), imageUri);
    ImageView imageView = (ImageView) findViewById(R.id.imgView);
    imageView.setImageBitmap(bitmap);
   }
}

Get Bitmap from an Uri [android]

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM