国产亚洲精品福利在线无卡一,国产精久久一区二区三区,亚洲精品无码国模,精品久久久久久无码专区不卡

當前位置: 首頁 > news >正文

網(wǎng)站建設怎樣上傳程序企業(yè)網(wǎng)站營銷的實現(xiàn)方式

網(wǎng)站建設怎樣上傳程序,企業(yè)網(wǎng)站營銷的實現(xiàn)方式,vs網(wǎng)站中的輪播怎么做,WordPress電影評分模板Android相機調用有原生的Camera和Camera2,我覺得調用代碼都太復雜了,CameraX調用代碼簡潔很多。 說明文檔:https://developer.android.com/jetpack/androidx/releases/camera?hlzh-cn 現(xiàn)有查到的調用資料都不夠新,對于外接攝像…

Android相機調用有原生的Camera和Camera2,我覺得調用代碼都太復雜了,CameraX調用代碼簡潔很多。

說明文檔:https://developer.android.com/jetpack/androidx/releases/camera?hl=zh-cn

現(xiàn)有查到的調用資料都不夠新,對于外接攝像頭(USB攝像頭)這類非前置也非后置攝像頭的設備調用,都說是沒有實現(xiàn)。舊版本的庫可能更多目標用戶是基于手機的,1.3.0-alpha03版本針對外接攝像頭有增加配置項(CameraSelector.LENS_FACING_EXTERNAL),使用該配置項可以實現(xiàn)外接攝像頭的調用。

0,攝像頭選擇可用值

    /** A camera on the devices that its lens facing is resolved. */public static final int LENS_FACING_UNKNOWN = -1;/** A camera on the device facing the same direction as the device's screen. */public static final int LENS_FACING_FRONT = 0;/** A camera on the device facing the opposite direction as the device's screen. */public static final int LENS_FACING_BACK = 1;/*** An external camera that has no fixed facing relative to the device's screen.** <p>The behavior of an external camera highly depends on the manufacturer. Currently it's* treated similar to a front facing camera with little verification. So it's considered* experimental and should be used with caution.*/@ExperimentalLensFacingpublic static final int LENS_FACING_EXTERNAL = 2;

1,在AndroidManifest.xml添加權限

    <uses-permission android:name="android.permission.CAMERA" /><uses-feature android:name="android.hardware.camera.any" />

2,在settings.gradle或build.gradle添加maven

    repositories {google()mavenCentral()maven { url 'https://jitpack.io' }}

3,在build.gradle添加依賴庫

    //攝像頭預覽庫implementation "androidx.camera:camera-core:1.3.0-alpha04"// CameraX Camera2 extensions[可選]拓展庫可實現(xiàn)人像、HDR、夜間和美顏、濾鏡但依賴于OEMimplementation "androidx.camera:camera-camera2:1.3.0-alpha04"// CameraX Lifecycle library[可選]避免手動在生命周期釋放和銷毀數(shù)據(jù)implementation "androidx.camera:camera-lifecycle:1.3.0-alpha04"// CameraX View class[可選]最佳實踐,最好用里面的PreviewView,它會自行判斷用SurfaceView還是TextureView來實現(xiàn)implementation 'androidx.camera:camera-view:1.3.0-alpha04'

4,開啟預覽代碼

    private ListenableFuture<ProcessCameraProvider> cameraProviderFuture;private PreviewView previewView;private ProcessCameraProvider cameraProvider;ImageView picture = null;@Overrideprotected void onCreate(Bundle savedInstanceState) {super.onCreate(savedInstanceState);setContentView(R.layout.activity_main);picture = (ImageView) findViewById(R.id.picture);previewView=findViewById(R.id.previewView);//初始化//高版本系統(tǒng)動態(tài)權限申請if (ContextCompat.checkSelfPermission(this, Manifest.permission.CAMERA) == PackageManager.PERMISSION_DENIED) {if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {requestPermissions(new String[]{Manifest.permission.CAMERA,}, 11);}} else {//啟動相機startCamera();}takePhoto.setOnClickListener(new View.OnClickListener() {@Overridepublic void onClick(View view) {takePhoto(picture);//取圖識別}});}@Overridepublic void onRequestPermissionsResult(int requestCode, @NonNull String[] permissions, @NonNull int[] grantResults) {super.onRequestPermissionsResult(requestCode, permissions, grantResults);if (requestCode==11){//獲取權限后,開啟攝像頭//啟動相機startCamera();}}private void startCamera() {// 請求 CameraProvidercameraProviderFuture = ProcessCameraProvider.getInstance(this);//檢查 CameraProvider 可用性,驗證它能否在視圖創(chuàng)建后成功初始化cameraProviderFuture.addListener(() -> {try {ProcessCameraProvider cameraProvider = cameraProviderFuture.get();bindPreview(cameraProvider);} catch (ExecutionException | InterruptedException e) {// No errors need to be handled for this Future.// This should never be reached.}}, ContextCompat.getMainExecutor(this));}//選擇相機并綁定生命周期和用例private void bindPreview(@NonNull ProcessCameraProvider cp) {this.cameraProvider=cp;Preview preview = new Preview.Builder().build();@SuppressLint("UnsafeOptInUsageError")CameraSelector cameraSelector = new CameraSelector.Builder().requireLensFacing(CameraSelector.LENS_FACING_BACK)//CameraSelector.LENS_FACING_EXTERNAL.build();preview.setSurfaceProvider(previewView.getSurfaceProvider());cameraProvider.unbindAll();//解綁組件cameraProvider.bindToLifecycle((LifecycleOwner) this, cameraSelector, preview);}//拍照,這里偷懶了,直接取了預覽控件的圖片,需要拍照的再去看看官方文檔吧public void takePhoto(View view){Log.e("OCR", "takePhoto");Bitmap bitmap = previewView.getBitmap();view.setBackground(new BitmapDrawable(getApplicationContext().getResources(),bitmap)); //show picture}@Overrideprotected void onDestroy() {super.onDestroy();cameraProvider.unbindAll();}

5,界面布局

<?xml version="1.0" encoding="utf-8"?>
<androidx.coordinatorlayout.widget.CoordinatorLayout xmlns:android="http://schemas.android.com/apk/res/android"xmlns:app="http://schemas.android.com/apk/res-auto"xmlns:tools="http://schemas.android.com/tools"android:layout_width="match_parent"android:layout_height="match_parent"tools:context=".MainActivity"><LinearLayoutandroid:layout_width="match_parent"android:layout_height="wrap_content"android:layout_margin="5dp"android:orientation="vertical"><androidx.camera.view.PreviewViewandroid:id="@+id/previewView"android:layout_width="300dp"android:layout_height="300dp"android:layout_gravity="center"/><Buttonandroid:id="@+id/take_photo"android:layout_width="match_parent"android:layout_height="wrap_content"android:layout_margin="5dp"android:text="取圖"/><ImageViewandroid:id="@+id/picture"android:layout_width="300dp"android:layout_height="300dp"android:layout_gravity="center"/></LinearLayout></androidx.coordinatorlayout.widget.CoordinatorLayout>

6,測試效果(文字識別部分請忽略)

s

7,庫的調用版本是比較新的,建議JDK版本不要太低,我使用的是16.0.2

新人入行,經(jīng)驗分享,如有所誤,歡迎指出~

版權歸屬:深圳市琪智科技有限公司-花花

http://m.aloenet.com.cn/news/30481.html

相關文章:

  • 做網(wǎng)站的畢設開題依據(jù)在線注冊網(wǎng)站
  • 如何在office做網(wǎng)站360站長平臺
  • 公司網(wǎng)站維護好做嗎百度移動端排名軟件
  • 網(wǎng)站建設外包流程網(wǎng)站排名優(yōu)化怎樣做
  • 萊蕪亓家網(wǎng)站優(yōu)化神馬網(wǎng)站關鍵詞排名價格
  • 網(wǎng)站建設在線視頻百度云搜索入口
  • diy做網(wǎng)站搜索關鍵詞的工具
  • 學做靜態(tài)網(wǎng)站怎么做電商生意
  • 織夢網(wǎng)站聯(lián)系我們的地圖怎么做關鍵詞搜索廣告
  • 湛江模板建站系統(tǒng)海外短視頻軟件
  • 哪里做網(wǎng)站最好小時seo加盟
  • 建設云南省癌癥中心網(wǎng)站關鍵詞優(yōu)化價格
  • 網(wǎng)站新聞對百度優(yōu)化有用嗎百度網(wǎng)盤搜索入口
  • 虛擬主機怎么弄網(wǎng)站南昌seo推廣
  • 網(wǎng)站專做盜版小說 會犯法嗎百度搜索指數(shù)排行榜
  • 諸城網(wǎng)絡營銷免費發(fā)seo外鏈平臺
  • 廈門大型企業(yè)網(wǎng)站開發(fā)公司高級seo招聘
  • 學校教育網(wǎng)站模板惡意點擊推廣神器
  • 有沒有好網(wǎng)站推薦提升網(wǎng)頁優(yōu)化排名
  • ppt做的好的網(wǎng)站有哪些樂事薯片軟文推廣
  • nb-iot網(wǎng)站開發(fā)百度付費推廣有幾種方式
  • 合肥晨曦網(wǎng)站建設百度競價關鍵詞怎么優(yōu)化
  • 東莞市國外網(wǎng)站建設平臺谷歌網(wǎng)頁版
  • 網(wǎng)站建設產(chǎn)業(yè)pest分析windows優(yōu)化軟件排行
  • 廣州企業(yè)網(wǎng)站建設推薦域名服務器ip地址查詢
  • 網(wǎng)站建設需要什么人才網(wǎng)絡營銷與直播電商專業(yè)介紹
  • 哪個做簡歷的網(wǎng)站比較好石家莊最新新聞事件
  • 網(wǎng)站做整站做優(yōu)化seo站點是什么意思
  • 網(wǎng)站開發(fā)報告步驟分析企業(yè)軟文
  • 淘寶seo搜索優(yōu)化seo關鍵字怎么優(yōu)化