2012-08-13 5 views
2

GalleryCamera에서 선택된 이미지를 자릅니다. 나는 대부분의 이미지를 자르지 않는다. 그것의 전화 번호는 onActivityResult()입니다. 아래는 제 코드입니다. 이미지를 자른 후 OK을 클릭 할 때마다 다음과 같은 로그 고양이 출력이 표시됩니다.이미지 자르기 중 오류가 발생했습니다.

코드 :

private void doCrop() { 
    Intent intent = new Intent("com.android.camera.action.CROP"); 
    intent.setType("image/*"); 

    List<ResolveInfo> list = getPackageManager().queryIntentActivities(
      intent, 0); 

    int size = list.size(); 
    if (size == 0) { 
     Toast.makeText(this, "Can not find image crop app", 
       Toast.LENGTH_SHORT).show(); 

     return; 
    } else { 
     intent.setData(mImageCaptureUri); 

     // intent.putExtra("outputX", 200); 
     // intent.putExtra("outputY", 200); 
     // intent.putExtra("aspectX", 1); 
     // intent.putExtra("aspectY", 1); 
     intent.putExtra("outputX", myImg.getWidth()); 
     intent.putExtra("outputY", myImg.getHeight()); 
     intent.putExtra("aspectX", 1); 
     intent.putExtra("aspectY", 1); 
     intent.putExtra("scale", true); 
     intent.putExtra("return-data", true); 
     intent.putExtra("outputFormat", 
       Bitmap.CompressFormat.PNG.toString()); 
     intent.putExtra("crop", "true"); 

     if (size == 1) { 
      Intent i = new Intent(intent); 
      ResolveInfo res = list.get(0); 

      i.setComponent(new ComponentName(res.activityInfo.packageName, 
        res.activityInfo.name)); 

      startActivityForResult(i, CROP_FROM); 
     } 
    } 

} 

로그 캣 :

08-13 15:59:29.220: D/skia(7247): WARNING: One-shot allocator has already allocated (alloc count = 1) 
08-13 15:59:29.290: D/skia(7247): WARNING: One-shot allocator has already allocated (alloc count = 1) 
08-13 15:59:30.140: D/dalvikvm(288): GC_EXPLICIT freed 8K, 8% free 6788K/7367K, paused 2ms+2ms 
08-13 15:59:34.110: D/dalvikvm(7247): GC_FOR_ALLOC freed 4824K, 44% free 10227K/18055K, paused 26ms 
08-13 15:59:34.110: I/dalvikvm-heap(7247): Grow heap (frag case) to 11.929MB for 1956256-byte allocation 
08-13 15:59:34.140: D/dalvikvm(7247): GC_FOR_ALLOC freed <1K, 33% free 12137K/18055K, paused 23ms 
08-13 15:59:34.190: D/dalvikvm(7247): GC_CONCURRENT freed 1K, 25% free 13662K/18055K, paused 2ms+3ms 
08-13 15:59:34.230: D/skia(7247): WARNING: One-shot allocator has already allocated (alloc count = 1) 
08-13 15:59:34.280: D/dalvikvm(7247): GC_FOR_ALLOC freed 2554K, 33% free 12132K/18055K, paused 30ms 
08-13 15:59:34.310: D/skia(7247): WARNING: One-shot allocator has already allocated (alloc count = 1) 
08-13 15:59:34.340: D/dalvikvm(7247): GC_FOR_ALLOC freed <1K, 27% free 13331K/18055K, paused 30ms 
08-13 15:59:34.390: D/dalvikvm(7247): GC_FOR_ALLOC freed 2000K, 33% free 12132K/18055K, paused 30ms 
08-13 15:59:34.420: D/skia(7247): WARNING: One-shot allocator has already allocated (alloc count = 1) 
08-13 15:59:34.450: D/dalvikvm(7247): GC_FOR_ALLOC freed <1K, 26% free 13430K/18055K, paused 33ms 
08-13 15:59:34.500: D/skia(7247): WARNING: One-shot allocator has already allocated (alloc count = 1) 
08-13 15:59:34.530: D/dalvikvm(7247): GC_FOR_ALLOC freed 2097K, 28% free 13152K/18055K, paused 30ms 
08-13 15:59:34.550: E/JavaBinder(7247): !!! FAILED BINDER TRANSACTION !!! 
08-13 15:59:34.560: W/InputManagerService(142): Window already focused, ignoring focus gain of: [email protected] 
08-13 15:59:39.620: D/dalvikvm(224): GC_EXPLICIT freed <1K, 31% free 17001K/24391K, paused 3ms+3ms 

답변

1

전체 소스 코드를 보시기 바랍니다.

동일한 projet을 사용하고 있습니다. 다음은 그 활동에 대한 코드는 다음과 같습니다

코드 :

이 와요 고마워요 작동
private void doCrop() { 
    final ArrayList<CropOption> cropOptions = new ArrayList<CropOption>(); 

    Intent intent = new Intent("com.android.camera.action.CROP"); 
    intent.setType("image/*"); 

    List<ResolveInfo> list = getPackageManager().queryIntentActivities(intent, 0); 

    int size = list.size(); 

    if (size == 0) {    
     Toast.makeText(this, "Can not find image crop app", Toast.LENGTH_SHORT).show(); 

     return; 
    } else { 
     intent.setData(mImageCaptureUri); 

     intent.putExtra("outputX", 200); 
     intent.putExtra("outputY", 200); 
     intent.putExtra("aspectX", 1); 
     intent.putExtra("aspectY", 1); 
     intent.putExtra("scale", true); 
     intent.putExtra("return-data", true); 

     if (size == 1) { 
      Intent i  = new Intent(intent); 
      ResolveInfo res = list.get(0); 

      i.setComponent(new ComponentName(res.activityInfo.packageName, res.activityInfo.name)); 

      startActivityForResult(i, CROP_FROM_CAMERA); 
     } else { 
      for (ResolveInfo res : list) { 
       final CropOption co = new CropOption(); 

       co.title = getPackageManager().getApplicationLabel(res.activityInfo.applicationInfo); 
       co.icon  = getPackageManager().getApplicationIcon(res.activityInfo.applicationInfo); 
       co.appIntent= new Intent(intent); 

       co.appIntent.setComponent(new ComponentName(res.activityInfo.packageName, res.activityInfo.name)); 

       cropOptions.add(co); 
      } 

      CropOptionAdapter adapter = new CropOptionAdapter(getApplicationContext(), cropOptions); 

      AlertDialog.Builder builder = new AlertDialog.Builder(this); 
      builder.setTitle("Choose Crop App"); 
      builder.setAdapter(adapter, new DialogInterface.OnClickListener() { 
       public void onClick(DialogInterface dialog, int item) { 
        startActivityForResult(cropOptions.get(item).appIntent, CROP_FROM_CAMERA); 
       } 
      }); 


      builder.setOnCancelListener(new DialogInterface.OnCancelListener() { 
       @Override 
       public void onCancel(DialogInterface dialog) { 

        if (mImageCaptureUri != null) { 
         getContentResolver().delete(mImageCaptureUri, null, null); 
         mImageCaptureUri = null; 
        } 
       } 
      }); 

      AlertDialog alert = builder.create(); 

      alert.show(); 
     } 
    } 
} 
+0

. 방금 ​​변경했습니다. intent.putExtra ("outputX", myImg.getWidth()); intent.putExtra ("outputY", myImg.getHeight()); to intent.putExtra ("outputX", 200); intent.putExtra ("outputY", 200); 그리고 제대로 작동합니다. 문제의 원인을 설명해 주시겠습니까 – Sniper

+0

답변을 수락 해 주셔서 감사합니다. 그것은 카메라 이미지에서 자르기를하기 위해 일반 안드로이드 카메라가 사용하는 기본 코드입니다. 그래서 그것을 검토하십시오. –

관련 문제