亚洲在线久爱草,狠狠天天香蕉网,天天搞日日干久草,伊人亚洲日本欧美

為了賬號安全,請及時綁定郵箱和手機立即綁定
已解決430363個問題,去搜搜看,總會有你想問的

相機意圖圖像預覽方向

相機意圖圖像預覽方向

森林海 2022-01-12 09:57:44
我使用以下代碼在 Android 中拍攝圖像:File image = new File(this.images_object_dir, loadedObjekt.getFilename());Uri uri = FileProvider.getUriForFile(this, FILE_PROVIDER, image);Intent intent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE);intent.putExtra(MediaStore.EXTRA_OUTPUT, uri);startActivityForResult(intent, CAMERA_ACTIVITY_CODE);在相機意圖中,我的華為 P20 Pro 上的圖像預覽始終處于縱向模式。在另一臺測試設備上,預覽圖像(您可以決定是否要重新拍攝圖像的圖像)也卡在“初始”旋轉中,看起來很難看。例如,如果您想以橫向模式拍攝圖像,則預覽將翻轉為縱向模式。有解決方案嗎?
查看完整描述

2 回答

?
瀟瀟雨雨

TA貢獻1833條經驗 獲得超4個贊

大約有 20 億臺 Android 設備,分布在大約 20,000 種設備型號中。這些設備型號中預裝了數十個(如果不是數百個)相機應用程序。用戶可以下載和安裝許多其他相機應用程序。

您的代碼可能會啟動其中任何一個。

在相機意圖中,我的華為 P20 Pro 上的圖像預覽始終處于縱向模式

這就是數百個相機應用程序的行為。

在另一臺測試設備上,預覽圖像(您可以決定是否要重新拍攝圖像的圖像)也卡在“初始”旋轉中,看起來很難看。

這就是數百個相機應用程序的行為。

相機應用程序不需要以這種方式運行。當然,相機應用程序根本不需要預覽圖像。

有解決方案嗎?

如果你想使用ACTION_IMAGE_CAPTURE,不。這數百個相機應用程序的行為取決于這些相機應用程序的開發人員,而不是您。

拍照還有其他選項,例如直接使用相機 API 或使用 Fotoapparat 或 CameraKit-Android 等第三方庫。


查看完整回答
反對 回復 2022-01-12
?
搖曳的薔薇

TA貢獻1793條經驗 獲得超6個贊

用于ExifInterface在解碼時檢查圖像的方向。然后旋轉圖像以獲得正確方向的所需圖像。


        BitmapFactory.Options options = new BitmapFactory.Options();

        options.inMutable = true;

        Bitmap decoded = BitmapFactory.decodeFile(filePath, options);


        if (decoded == null) return null;


        try {

            ExifInterface exif = new ExifInterface(filePath);

            int orientation = exif.getAttributeInt(ExifInterface.TAG_ORIENTATION,

                    ExifInterface.ORIENTATION_NORMAL);

            int rotation = 0;

            if (orientation == ExifInterface.ORIENTATION_ROTATE_90) {

                rotation = 90;

            } else if (orientation == ExifInterface.ORIENTATION_ROTATE_270) {

                rotation = 270;

            } else if (orientation == ExifInterface.ORIENTATION_ROTATE_180) {

                rotation = 180;

            }


            if (rotation != 0) {

                Matrix matrix = new Matrix();

                matrix.postRotate(rotation);

                Bitmap newBitmap = Bitmap.createBitmap(decoded, 0, 0, decoded.getWidth(),

                        decoded.getHeight(), matrix, true);

                decoded.recycle();

                Runtime.getRuntime().gc();

                decoded = newBitmap;

            }


        } catch (IOException e) {

            e.printStackTrace();

        }

如果您想使用支持庫來支持 API 級別較低的設備,請使用以下依賴項:


implementation 'com.android.support:exifinterface:27.1.1'

并導入 android.support.media.ExifInterface


查看完整回答
反對 回復 2022-01-12
  • 2 回答
  • 0 關注
  • 163 瀏覽
慕課專欄
更多

添加回答

舉報

0/150
提交
取消
微信客服

購課補貼
聯系客服咨詢優惠詳情

幫助反饋 APP下載

慕課網APP
您的移動學習伙伴

公眾號

掃描二維碼
關注慕課網微信公眾號