2013-04-28 1 views
0

갤러리보기를 사용하여 사용자가 이미지를 선택할 수 있습니다. 사용자가 이미지를 선택하면 "자르기 페이지"로 넘어갑니다. 나는 내 데이터가 null하여 onActivityResult로 돌아가 내가 자른 이미지를 retreive 못할 때이미지 검색 및 자르기 후 데이터가 반환되지 않습니다.

Intent photoPickerIntent = new Intent(Intent.ACTION_PICK); 
photoPickerIntent.setType("image/*"); 
photoPickerIntent.putExtra("crop", "true"); 
startActivityForResult(photoPickerIntent, 1); 

(이 내가했던대로 사용자 정의 활동하지 않습니다).

누구든지 해결 방법을 알고 있습니까? 감사합니다.

답변

0

사용이 코드

private static final String TEMP_PHOTO_FILE = "temporary_holder.jpg"; 

Intent photoPickerIntent = new Intent(Intent.ACTION_PICK, 
    android.provider.MediaStore.Images.Media.EXTERNAL_CONTENT_URI); 
photoPickerIntent.setType("image/*"); 
photoPickerIntent.putExtra("crop", "true"); 
photoPickerIntent.putExtra(MediaStore.EXTRA_OUTPUT, getTempUri()); 
photoPickerIntent.putExtra("outputFormat", Bitmap.CompressFormat.JPEG.toString()); 
startActivityForResult(photoPickerIntent, REQ_CODE_PICK_IMAGE); 

private Uri getTempUri() { 
    return Uri.fromFile(getTempFile()); 
} 

private File getTempFile() { 

    if (Environment.getExternalStorageState().equals(Environment.MEDIA_MOUNTED)) { 

    File file = new File(Environment.getExternalStorageDirectory(),TEMP_PHOTO_FILE); 
    try { 
     file.createNewFile(); 
    } catch (IOException e) {} 

    return file; 
} else { 

    return null; 
    } 
} 

protected void onActivityResult(int requestCode, int resultCode, 
    Intent imageReturnedIntent) { 

super.onActivityResult(requestCode, resultCode, imageReturnedIntent); 

switch (requestCode) { 
    case REQ_CODE_PICK_IMAGE: 
     if (resultCode == RESULT_OK) { 
      if (imageReturnedIntent!=null) { 

       File tempFile = getTempFile(); 

       String filePath= Environment.getExternalStorageDirectory() 
        +"/"+TEMP_PHOTO_FILE; 
       System.out.println("path "+filePath); 


       Bitmap selectedImage = BitmapFactory.decodeFile(filePath); 
       _image = (ImageView) findViewById(R.id.image); 
       _image.setImageBitmap(selectedImage); 

       if (tempFile.exists()) tempFile.delete(); 
      } 
     } 
    }  
} 

는 권한을

추가개
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" /> 

Source

관련 문제