2015-02-09 48 views
0

我試圖讓三星s4上的裁剪圖像工作,但它不顯示裁剪屏幕。Android在三星s4上發佈裁剪圖像

這是我正在使用的代碼。

private void openCamera() { 
    Intent intent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE); 

    intent.putExtra(MediaStore.EXTRA_OUTPUT, 
      MediaStore.Images.Media.EXTERNAL_CONTENT_URI.toString()); 
    // ******** code for crop image 
    intent.setType("image/*"); 
    intent.putExtra("crop", "true"); 
    intent.putExtra("aspectX", 3); 
    intent.putExtra("aspectY", 4); 
    intent.putExtra("outputX", 180); 
    intent.putExtra("outputY", 220); 

    try { 

     intent.putExtra("return-data", true); 
     startActivityForResult(intent, 1); 

    } catch (ActivityNotFoundException e) { 
     // Do nothing for now 
     String s = e.getMessage(); 
     String test = e.getLocalizedMessage(); 
    } 
} 

回答

1

您使用的意圖是用於捕獲圖像。 您需要先捕捉圖像,然後在其上應用裁剪。 喲可以這樣做。

private void openCamera() { 
Intent intent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE); 

intent.putExtra(MediaStore.EXTRA_OUTPUT, 
     MediaStore.Images.Media.EXTERNAL_CONTENT_URI.toString()); 

try { 

    intent.putExtra("return-data", true); 
    startActivityForResult(intent, 1); 

} 
catch (ActivityNotFoundException e) { 
    // Do nothing for now 
     } 
} 

onActivityResult從哪裏獲取捕獲的圖像。應用作物。

private void performCrop() { 
    try { 
     Intent cropIntent = new Intent("com.android.camera.action.CROP");   cropIntent.setDataAndType(mUri, "image/*"); 
     // set crop properties 
     cropIntent.putExtra("crop", "true"); 
     // indicate aspect of desired crop 
     cropIntent.putExtra("aspectX", 1); 
     cropIntent.putExtra("aspectY", 1); 
     // indicate output X and Y 
     cropIntent.putExtra("outputX", 150); 
     cropIntent.putExtra("outputY", 150); 
     // retrieve data on return 
     cropIntent.putExtra("return-data", true); 
     // start the activity - we handle returning in onActivityResult 
     startActivityForResult(cropIntent, 12); 
    } 
    // respond to users whose devices do not support the crop action 
    catch (ActivityNotFoundException anfe) { 
     // display an error message 
     String errorMessage = "Whoops - your device doesn't support the crop action!"; 
     Toast.makeText(Signature.this, errorMessage, Toast.LENGTH_SHORT) 
       .show(); 

    } 
} 
+0

非常感謝。它解決了我的問題:) – dogwasstar 2015-02-10 04:51:13

+0

我的榮幸:)。你可以接受這個答案。 – justDroid 2015-02-10 05:26:28