如何将选定的图像从库传递到位图

时间:2013-11-15 07:13:20

标签: android

Bitmap bitmap = BitmapFactory.decodeResource(getResources(),R.drawable.apples); 

 if (resultCode == RESULT_OK) {
                if (requestCode == SELECT_PICTURE) {
                Log.i("Image select","Selected Image");
                    selectedImageUri = data.getData();
                    selectedImagePath = getPath(selectedImageUri);
                    System.out.println("Image Path : " + selectedImagePath);
               //     Toast.makeText(SocialTwitter.this, "Message not posted on " + selectedImagePath, Toast.LENGTH_LONG).show();
                    img.setImageURI(selectedImageUri);

代替资源我想通过selectedImageUri我怎么能帮助我 感谢

2 个答案:

答案 0 :(得分:0)

Uri targetUri = data.getData();
            String selectedImagePath = getPath(targetUri);
            Bitmap bitmap2 = BitmapFactory.decodeFile(selectedImagePath);


BitmapDrawable bd = new BitmapDrawable(getResources(), bitmap2);
yourImageView.setImageDrawable(bd);

答案 1 :(得分:0)

这是获取位图的方法

   if (requestCode == SELECT_PICTURE)
   {
      Uri imageUri = data.getData();
      Bitmap bitmap = MediaStore.Images.Media.getBitmap(this.getContentResolver(), imageUri);
   }