Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/wpf/14.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Android 来自OnActivityResult和imageview的URI_Android - Fatal编程技术网

Android 来自OnActivityResult和imageview的URI

Android 来自OnActivityResult和imageview的URI,android,Android,在我的应用程序中,一个用户点击一个按钮打开Choser来选择一张图片。在我的活动结果上,代码是 public void onActivityResult(int requestCode, int resultCode, Intent data) { if (resultCode == RESULT_OK) { if (requestCode == SELECT_PICTURE_REQUEST_CODE) { Uri sele

在我的应用程序中,一个用户点击一个按钮打开Choser来选择一张图片。在我的活动结果上,代码是

public void onActivityResult(int requestCode, int resultCode, Intent data) {
        if (resultCode == RESULT_OK) {
            if (requestCode == SELECT_PICTURE_REQUEST_CODE) {
                Uri selectedImageUri = data.getData();
                if(selectedImageUri!=null){
                    imageviewTest.setImageURI(selectedImageUri)

                }else{

                }

            }
        }
 }
图像不显示。我想知道为什么?我注意到这个论坛上的一些人将这个值传递给contentresolver,这是为什么?这条路难道还不够吗


谢谢

谢谢!这很有效。当显示图片时,我应该使用压缩方法吗?还是抽样方法?
public void onActivityResult(int requestCode, int resultCode, Intent data) {
        if (resultCode == RESULT_OK) {
            if (requestCode == SELECT_PICTURE_REQUEST_CODE) {
                BitmapFactory.Options bfOptions =new BitmapFactory.Options();
                Uri selectedImage = data.getData();
                if(selectedImage!=null){
                    String galleryImatePath = getRealPathFromURI(selectedImage);
                    try{

                            bfOptions.inDither=false;          //Disable Dithering mode
                            bfOptions.inPurgeable=true;        //Tell to gc that whether it needs free memory, the Bitmap can be cleared
                            bfOptions.inInputShareable=true;   //Which kind of reference will be used to recover the Bitmap data after being clear, when it will be used in the future 
                            bfOptions.inSampleSize=5;
                            bfOptions.inTempStorage=new byte[32 * 1024];
                            InputStream stream = getContentResolver().openInputStream(selectedImage);
                            final Bitmap myImage = BitmapFactory.decodeStream(stream, null , bfOptions);
                            ByteArrayOutputStream bos = new ByteArrayOutputStream();
                            myImage.compress(Bitmap.CompressFormat.JPEG, 100, bos);
                            bitmapdata = bos.toByteArray();
                            imageviewTest.setImageBitmap(myImage)

                }else{

                }

            }
        }
 }

public String getRealPathFromURI(Uri contentUri) {
    String[] proj = { MediaStore.Images.Media.DATA };
    Cursor cursor = managedQuery(contentUri, proj, null, null, null);
    int column_index = cursor.getColumnIndexOrThrow(MediaStore.Images.Media.DATA);
    cursor.moveToFirst();
    return cursor.getString(column_index);
}