簡體   English   中英

如何使用裁切選項直接打開圖像

[英]How to open Image directly with crop option

我想裁剪圖像,我能夠實現這一點。

我的代碼是

Intent cropIntent = new Intent(Intent.ACTION_PICK,
                android.provider.MediaStore.Images.Media.EXTERNAL_CONTENT_URI);         
        cropIntent.setDataAndType(fileUri, "image/*");
        // set crop properties
        cropIntent.putExtra("crop", "true");    
        cropIntent.putExtra("return-data", true);       
        startActivityForResult(cropIntent, CROP_PIC);

其中fileUri包含我要從Gallery裁剪的圖像路徑的URI。

使用此代碼,警報將打開,以選擇應用程序以選擇圖像,我想知道當我已經傳遞了圖像路徑時,為什么它會要求選擇應用程序以打開圖像,以及當我選擇應用程序(通過Gallery)時,我必須從Gallery中選擇圖像播種。

我想要一個解決方案,使用該解決方案,我的圖像僅通過裁切選項打開,而無需詢問選擇要使用哪個應用程序打開?

可能嗎? 請幫助我實現它...

試試這個:

     String filename = "image.png";
     String path = "/mnt/sdcard/" + filename;
     File f = new File(path);  //  
     Uri imgUri= Uri.fromFile(f);  
     Intent intent = new Intent("com.android.camera.action.CROP");  
            intent.setDataAndType(imgUri, "image/*");  
            intent.putExtra("crop", "true");  
            intent.putExtra("aspectX", 1);  
            intent.putExtra("aspectY", 1);  
            intent.putExtra("outputX", 50);  
            intent.putExtra("outputY", 50);  
            intent.putExtra("return-data", true);
            startActivityForResult(intent, 1);

使用本地作物不是一個好的解決方案,因為每種作物的行為都不同。 我遇到了一些錯誤,因為無法保存文件,寬高比不正確,也許還有其他錯誤。
我認為從圖庫中挑選照片后使用自定義作物庫的最佳解決方案。
有一些很好的庫,例如https://github.com/jdamcd/android-crophttps://github.com/lvillani/android-cropimagehttps://github.com/edmodo/cropper

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM