最新国产好看的视频,伊人天堂AV在线,国产Aaaaaa视频,蜜臀视频在线观看一区,人妻av色图,密臀久久久精品影片,青青视频免费观看毛片,久草在线观看视,国产三级精品色情在线

Android自定義相機(jī)、預(yù)覽區(qū)域裁剪

 更新時(shí)間:2022年05月19日 17:16:02   作者:唐諾  
這篇文章主要為大家詳細(xì)介紹了Android自定義相機(jī)、預(yù)覽區(qū)域裁剪,文中示例代碼介紹的非常詳細(xì),具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下

本文實(shí)例為大家分享了Android自定義相機(jī),預(yù)覽區(qū)域裁剪的具體代碼,供大家參考,具體內(nèi)容如下

寫法一:

預(yù)覽區(qū)域裁剪,方法調(diào)用:

//按照比例進(jìn)行裁剪頭像區(qū)域
Bitmap ? resultBitmap = getScaleImage(resultBitmap,
?(int) cuttingAreaView.getX(),
? (int) cuttingAreaView.getY(),?
? cuttingAreaView.getWidth(),?
? cuttingAreaView.getHeight(),?
? mSurfaceView.getWidth(),?
? mSurfaceView.getHeight());
/**
? ? ?* 按照比例裁剪圖片
? ? ?*
? ? ?* @param source
? ? ?* @param cuttingAreaX ?預(yù)覽view的X坐標(biāo)
? ? ?* @param cuttingAreaY
? ? ?* @param cuttingAreaWidth
? ? ?* @param cuttingAreaHeight
? ? ?* @param displayWidth
? ? ?* @param displayHeight
? ? ?* @return
? ? ?*/
? ? private Bitmap getScaleImage(Bitmap source, int cuttingAreaX, int cuttingAreaY, int cuttingAreaWidth, int cuttingAreaHeight, int displayWidth, int displayHeight) {
? ? ? ? int sourceWidth = source.getWidth();
? ? ? ? int sourceHeight = source.getHeight();
? ? ? ? LegoLog.d("sourceWidth:" + sourceWidth + ",sourceHeight:" + sourceHeight + ",cuttingAreaX:" + cuttingAreaX + ",cuttingAreaY:" + cuttingAreaY + ",cuttingAreaWidth:" + cuttingAreaWidth + ",cuttingAreaHeight:" + cuttingAreaHeight + ",displayWidth:" + displayWidth + ",displayHeight:" + displayHeight);
? ? ? ? int sourceCuttingAreaX = cuttingAreaX * sourceWidth / displayWidth;
? ? ? ? int sourceCuttingAreaY = cuttingAreaY * sourceHeight / displayHeight;
? ? ? ? int sourceCuttingAreaWidth = cuttingAreaWidth * sourceWidth / displayWidth;
? ? ? ? int sourceCuttingAreaHeight = cuttingAreaHeight * sourceHeight / displayHeight;
? ? ? ? LegoLog.d("sourceWidth:" + sourceWidth + ",sourceHeight:" + sourceHeight + ",sourceCuttingAreaX:" + sourceCuttingAreaX + ",sourceCuttingAreaY:" + sourceCuttingAreaY + ",sourceCuttingAreaWidth:" + sourceCuttingAreaWidth + ",sourceCuttingAreaHeight:" + sourceCuttingAreaHeight);
? ? ? ? return Bitmap.createBitmap(source, sourceCuttingAreaX, sourceCuttingAreaY, sourceCuttingAreaWidth, sourceCuttingAreaHeight, null, false);
? ? }

其他方法:

private void initParameters(Camera camera) {
? ? ? ? try {
? ? ? ? ? ? mParameters = camera.getParameters();
? ? ? ? ? ? mParameters.setPreviewFormat(ImageFormat.NV21);
? ? ? ? ? ? //獲取與指定寬高相等或最接近的尺寸
? ? ? ? ? ? //設(shè)置預(yù)覽尺寸
? ? ? ? ? ? Camera.Size bestPreviewSize = getBestSize(mSurfaceView.getWidth(), mSurfaceView.getHeight(), mParameters.getSupportedPreviewSizes());
? ? ? ? ? ? if (bestPreviewSize != null) {
? ? ? ? ? ? ? ? mParameters.setPreviewSize(bestPreviewSize.width, bestPreviewSize.height);
? ? ? ? ? ? }
? ? ? ? ? ? //設(shè)置保存圖片尺寸
? ? ? ? ? ? Camera.Size bestPicSize = getBestSize(PIC_WIDTH, PIC_HEIGHT, mParameters.getSupportedPictureSizes());
? ? ? ? ? ? if (bestPicSize != null) {
? ? ? ? ? ? ? ? mParameters.setPictureSize(bestPicSize.width, bestPicSize.height);
? ? ? ? ? ? }
? ? ? ? ? ? //對(duì)焦模式
? ? ? ? ? ? if (isSupportFocus(Camera.Parameters.FOCUS_MODE_CONTINUOUS_PICTURE)) {
? ? ? ? ? ? ? ? mParameters.setFocusMode(Camera.Parameters.FOCUS_MODE_CONTINUOUS_PICTURE);
? ? ? ? ? ? }
? ? ? ? ? ? camera.setParameters(mParameters);
? ? ? ? } catch (Exception e) {
? ? ? ? ? ? e.printStackTrace();
? ? ? ? }
? ? }
? ??
? ? private Camera.Size getBestSize(int targetWidth, int targetHeight, List<Camera.Size> sizeList) {
? ? ? ? Camera.Size bestSize = null;
? ? ? ? float targetRatio = ((float) targetHeight / targetWidth); ?//目標(biāo)大小的寬高比
? ? ? ? float minDiff = targetRatio;
? ? ? ? for (Camera.Size size : sizeList) {
? ? ? ? ? ? if (size.width == targetHeight && size.height == targetWidth) {
? ? ? ? ? ? ? ? bestSize = size;
? ? ? ? ? ? ? ? break;
? ? ? ? ? ? }
? ? ? ? ? ? float supportedRatio = (float) size.width / size.height;
? ? ? ? ? ? if (Math.abs(supportedRatio - targetRatio) < minDiff) {
? ? ? ? ? ? ? ? minDiff = Math.abs(supportedRatio - targetRatio);
? ? ? ? ? ? ? ? bestSize = size;
? ? ? ? ? ? }
? ? ? ? }
? ? ? ? return bestSize;
? ? }

參考【人車核驗(yàn)】CaptureManager.java

寫法二:

Bitmap bitmap = BitmapFactory.decodeFile(originalFile.getPath());//原圖

//計(jì)算裁剪位置
float left, top, right, bottom;
left = (float) scanView.getLeft() / (float) cameraPreview.getWidth();
top = ((float) containerView.getTop() - (float) cameraPreview.getTop()) / (float) cameraPreview.getHeight();
right = (float) scanView.getRight() / (float) cameraPreview.getWidth();
bottom = (float) containerView.getBottom() / (float) cameraPreview.getHeight();

//裁剪及保存到文件
Bitmap cropBitmap = Bitmap.createBitmap(bitmap,
? ? ? (int) (left * (float) bitmap.getWidth()),
? ? ? (int) (top * (float) bitmap.getHeight()),
? ? ? (int) ((right - left) * (float) bitmap.getWidth()),
? ? ? (int) ((bottom - top) * (float) bitmap.getHeight()));

參考:MobileCheck

以上就是本文的全部?jī)?nèi)容,希望對(duì)大家的學(xué)習(xí)有所幫助,也希望大家多多支持腳本之家。

相關(guān)文章

  • Android?獲取實(shí)時(shí)網(wǎng)速實(shí)現(xiàn)詳解

    Android?獲取實(shí)時(shí)網(wǎng)速實(shí)現(xiàn)詳解

    這篇文章主要為大家介紹了Android?獲取實(shí)時(shí)網(wǎng)速實(shí)現(xiàn)詳解,有需要的朋友可以借鑒參考下,希望能夠有所幫助,祝大家多多進(jìn)步,早日升職加薪
    2022-11-11
  • Jetpack?Compose?分步指南教程詳解

    Jetpack?Compose?分步指南教程詳解

    這篇文章主要為大家介紹了Jetpack?Compose?分步指南教程詳解,有需要的朋友可以借鑒參考下,希望能夠有所幫助,祝大家多多進(jìn)步,早日升職加薪
    2022-11-11
  • 使用 Lambda 取代 Android 中的匿名類

    使用 Lambda 取代 Android 中的匿名類

    本文主要介紹使用Lambda 取代 Android 中的匿名類的資料,這里這里了相關(guān)資料及簡(jiǎn)單示例代碼幫助大家學(xué)習(xí)參考此部分的知識(shí),有需要的小伙伴可以參考下
    2016-09-09
  • Android中ViewFlipper和AdapterViewFlipper使用的方法實(shí)例

    Android中ViewFlipper和AdapterViewFlipper使用的方法實(shí)例

    ViewFlipper和AdapterViewFlipper是Android自帶的一個(gè)多頁面管理控件,下面這篇文章主要給大家介紹了關(guān)于Android中ViewFlipper和AdapterViewFlipper使用的相關(guān)資料,文中通過實(shí)例代碼介紹的非常詳細(xì),需要的朋友可以參考下
    2022-05-05
  • Android實(shí)現(xiàn)一個(gè)絲滑的自動(dòng)輪播控件實(shí)例代碼

    Android實(shí)現(xiàn)一個(gè)絲滑的自動(dòng)輪播控件實(shí)例代碼

    輪播圖對(duì)大家來說應(yīng)該再熟悉不過了,下面這篇文章主要給大家介紹了關(guān)于Android實(shí)現(xiàn)一個(gè)絲滑的自動(dòng)輪播控件的相關(guān)資料,文中通過示例代碼介紹的非常詳細(xì),需要的朋友可以參考借鑒,下面隨著小編來一起學(xué)習(xí)學(xué)習(xí)吧
    2018-08-08
  • Android bindService的使用與Service生命周期案例詳解

    Android bindService的使用與Service生命周期案例詳解

    這篇文章主要介紹了Android bindService的使用與Service生命周期案例詳解,本篇文章通過簡(jiǎn)要的案例,講解了該項(xiàng)技術(shù)的了解與使用,以下就是詳細(xì)內(nèi)容,需要的朋友可以參考下
    2021-09-09
  • 詳解Android平臺(tái)JSON預(yù)覽(JSON-handle)

    詳解Android平臺(tái)JSON預(yù)覽(JSON-handle)

    這篇文章主要介紹了Android平臺(tái)JSON預(yù)覽(JSON-handle),小編覺得挺不錯(cuò)的,現(xiàn)在分享給大家,也給大家做個(gè)參考。一起跟隨小編過來看看吧
    2018-09-09
  • Android實(shí)現(xiàn)百度地圖兩點(diǎn)畫弧線

    Android實(shí)現(xiàn)百度地圖兩點(diǎn)畫弧線

    這篇文章主要為大家詳細(xì)介紹了Android實(shí)現(xiàn)百度地圖兩點(diǎn)畫弧線,具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下
    2019-01-01
  • Android 監(jiān)聽WiFi的開關(guān)狀態(tài)實(shí)現(xiàn)代碼

    Android 監(jiān)聽WiFi的開關(guān)狀態(tài)實(shí)現(xiàn)代碼

    這篇文章主要介紹了Android 監(jiān)聽WiFi的開關(guān)狀態(tài)實(shí)現(xiàn)代碼的相關(guān)資料,需要的朋友可以參考下
    2017-05-05
  • Android返回鍵功能的實(shí)現(xiàn)方法

    Android返回鍵功能的實(shí)現(xiàn)方法

    這篇文章主要介紹了Android返回鍵功能的實(shí)現(xiàn)方法,實(shí)例分析了Android返回鍵的原理與具體的功能實(shí)現(xiàn)代碼,非常具有實(shí)用價(jià)值,需要的朋友可以參考下
    2015-02-02

最新評(píng)論

兰溪市| 定结县| 隆尧县| 甘德县| 定南县| 大足县| 阿克陶县| 仁布县| 尼玛县| 花莲县| 阳曲县| 麻阳| 鄂温| 中宁县| 茌平县| 农安县| 吉木乃县| 会东县| 通山县| 连云港市| 大同市| 平原县| 莎车县| 九台市| 措美县| 五台县| 成武县| 岐山县| 西和县| 建昌县| 合川市| 榕江县| 精河县| 湾仔区| 都安| 涟水县| 高淳县| 罗源县| 安阳市| 集贤县| 和林格尔县|