Warning: file_get_contents(/data/phpspider/zhask/data//catemap/7/image/5.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图像库裁剪图像并设置图像视图_Android_Image_Android Intent_Imageview - Fatal编程技术网

Android图像库裁剪图像并设置图像视图

Android图像库裁剪图像并设置图像视图,android,image,android-intent,imageview,Android,Image,Android Intent,Imageview,我在使用gallery意图返回的对象设置ImageView时遇到一些问题。我一定是做错了什么,但当我调试它时,一切似乎都在正确的位置。它没有抛出任何异常,只是将我的图像更改为零 我试图按照stackoverflow的其他指南和教程来获得我的答案,但我无法让它工作 这称画廊很好,但它不允许croping public void onViewCreated(View view, Bundle savedInstanceState) { final ImageView profileImage

我在使用gallery意图返回的对象设置ImageView时遇到一些问题。我一定是做错了什么,但当我调试它时,一切似乎都在正确的位置。它没有抛出任何异常,只是将我的图像更改为零

我试图按照stackoverflow的其他指南和教程来获得我的答案,但我无法让它工作

这称画廊很好,但它不允许croping

public void onViewCreated(View view, Bundle savedInstanceState) {
   final ImageView profileImage = (ImageView) view.findViewById(R.id.profile_user_image);
    profileImage.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            Intent i = new Intent(Intent.ACTION_PICK, android.provider.MediaStore.Images.Media.EXTERNAL_CONTENT_URI);
            startActivityForResult(i, RESULT_LOAD_IMAGE);
        }
    });
}

@Override
public void onActivityResult(int requestCode, int resultCode, Intent  data) {
    super.onActivityResult(requestCode, resultCode, data);
    if (requestCode == RESULT_LOAD_IMAGE && resultCode == Activity.RESULT_OK && null != data) {
        if (requestCode == RESULT_LOAD_IMAGE && resultCode == Activity.RESULT_OK && null != data) {
            Uri picUri = data.getData();
            String[] filePathColumn = {MediaStore.Images.Media.DATA};
            Cursor cursor = getActivity().getContentResolver().query(picUri,
                    filePathColumn, null, null, null);
            cursor.moveToFirst();
            int columnIndex = cursor.getColumnIndex(filePathColumn[0]);
            filePath = cursor.getString(columnIndex);
            cursor.close();

                    // Set The Bitmap Data To ImageView
                    BitmapFactory.Options o = new BitmapFactory.Options();
                    o.inPreferredConfig = Bitmap.Config.ARGB_8888;
                    o.inScaled = true;
                    ImageView bitmapview = (ImageView) _this.findViewById(R.id.profile_user_image);

                    bitmapview.setScaleType(ImageView.ScaleType.FIT_XY);
            //bitmapview.setImageResource(R.drawable.female_icon);  // KNOWN FILE
            bitmapview.setImageBitmap(BitmapFactory.decodeFile(filePath,o)); // Gallery File. 


        }
    }
}
我不知道我错过了什么 ImageView限制为150dp x 150dp


我曾尝试将其更改为工作正常的已知资源,但无论我如何尝试,每次使用此方法都会失败

使用
com.android.camera.action.crop
在android中裁剪图像。从库中拾取图像url后

Intent i = new Intent("com.android.camera.action.CROP");  
i.setClassName("com.android.camera", "com.android.camera.CropImage");  
File f = new File(filePath);  
Uri uri = Uri.fromFile(f);  
i.setData(uri);  
i.putExtra("crop", "true");  
i.putExtra("aspectX", 1);  
i.putExtra("aspectY", 1);  
i.putExtra("outputX", 96);  
i.putExtra("outputY", 96);  
i.putExtra("noFaceDetection", true);  


intent.putExtra("return-data", true);                                  
startActivityForResult(intent, REQUEST_CROP_ICON);
当图片选择时,将选择“活动返回”以保存内容。在onActivityResult中:

Bundle extras = data.getExtras();  
if(extras != null ) {  
    Bitmap photo = extras.getParcelable("data");  
    ByteArrayOutputStream stream = new ByteArrayOutputStream();  
    photo.compress(Bitmap.CompressFormat.JPEG, 75, stream);  
        / / The stream to write to a file or directly using the
}