Android 이미지 갤러리 이미지 자르기 및 ImageView 설정 (Android Image Gallery Crop Image and set ImageView)


문제 설명

Android 이미지 갤러리 이미지 자르기 및 ImageView 설정 (Android Image Gallery Crop Image and set ImageView)

갤러리 인텐트에서 반환된 개체로 ImageView를 설정하는 데 몇 가지 문제가 있습니다. 내가 뭔가 잘못하고 있어야 하지만 디버그할 때 모든 것이 올바른 위치에 있는 것 같습니다. 예외를 던지지 않고 내 이미지를 아무 것도 변경하지 않습니다.

제 답변을 얻기 위해 stackoverflow에 대한 다른 가이드 및 자습서를 따르려고 했지만 제대로 작동하지 않습니다.

갤러리를 잘 부르지만 자르기를 허용하지 않습니다...

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로 제한됩니다.

잘 작동하는 알려진 리소스로 변경하려고 시도했지만 이 방법을 사용하는 것은 내가 무엇을 시도하든 매번 실패합니다.


참조 솔루션

방법 1:

crop image in android by using com.android.camera.action.CROP. after picking image url from gallery.

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);

When the picture select Activity return will be selected to save the contents.in 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
}

(by 173901vishal jangid)

참조 문서

  1. Android Image Gallery Crop Image and set ImageView (CC BY‑SA 2.5/3.0/4.0)

#android-intent #image #imageview #Android






관련 질문

인텐트를 사용하여 메시지 작성 열기 (Opening create message using an intent)

다른 데이터로 일부 인텐트를 생성하더라도 알림에서 동일한 추가 데이터를 얻습니다. (I get the same extra data from notifications even if I create some intents with different data)

내 앱의 피드백 양식에 채워진 텍스트를 내 이메일 주소로 가져오는 방법은 무엇입니까? 자세한 내용을 참조하십시오 (How to get the text filled in feedback form of my app to my email address? Please see details)

Android 이미지 갤러리 이미지 자르기 및 ImageView 설정 (Android Image Gallery Crop Image and set ImageView)

xamarin에서 Android 활동 간에 데이터를 전달할 수 없습니다. (Can't pass data between android activities in xamarin)

모든 애플리케이션에 대한 Android 앱에서 데이터 공유 (Share Data in android app for all applications)

zxing이 브라우저에서 URL을 열도록 하거나 스캔 후 번호를 다이얼하는 방법 (How to make zxing open a URL in a browser or dial a number after scanning)

Android 암시적 의도 유효성 검사 (Android implicit intents validation)

kaldi 설치 시 libmkl_tbb_thread.so sth 관련 문제 (A problem related to libmkl_tbb_thread.so sth when installing kaldi)

Intent를 통해 데이터 전달 및 수신 (Passing data through Intent and receiving it)

android studio에서 인텐트를 통해 여러 콘텐츠를 보내는 방법 (how can i send multiple contents through intent in android studio)

Kotlin의 다른 EditText 값에 대한 의도 EditText 값 (Intent EditText values to another EditText values in Kotlin)







코멘트