[英]Cropping an image in android without using intents
目前我使用默認的Android相機意圖來裁剪圖像。 但是這在某些設備中無法正常工作。 在純Android設備中,不會調用裁剪或返回數據為空。 有沒有其他方法來實現相同的目標。
目前我使用以下代碼開始裁剪,
Intent cropIntent = new Intent("com.android.camera.action.CROP");
cropIntent.setType("image/*");
if(picUri != null) {
cropIntent.setDataAndType(picUri, "image/*");
}
String tmpName = imageDir.getAbsolutePath() + File.separator + "img.jpg";
File tmpFile = new File(tmpName);
if (tmpFile.exists()) {
tmpFile.delete();
}
Uri tmpUri = Uri.fromFile(tmpFile);
cropIntent.putExtra("crop", "true");
cropIntent.putExtra("aspectX", 16);
cropIntent.putExtra("aspectY", 9);
cropIntent.putExtra("outputX", 320);
cropIntent.putExtra("outputY", 180);
cropIntent.putExtra("return-data", true);
cropIntent.putExtra(MediaStore.EXTRA_OUTPUT, tmpUri);
startActivityForResult(cropIntent, PIC_CROP);
如果圖像可以加載到內存中,您可以使用BitmapFactory.decodeFile加載到Bitmap,並使用createBitmap在Bitmap上進行裁剪 。 小心使用任意圖像執行此操作,因為如果內存不足以加載圖像,則解碼將崩潰。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.