CameraX, এক্সটেনশন অ্যাক্সেস করার জন্য একটি এক্সটেনশন API প্রদান করে যা ডিভাইস প্রস্তুতকারকরা বিভিন্ন Android ডিভাইসে প্রয়োগ করেছেন। কাজ করে এমন এক্সটেনশন মোডের তালিকা দেখতে, ক্যামেরা এক্সটেনশন দেখুন।
এক্সটেনশন কাজ করে এমন ডিভাইসের তালিকা দেখতে, কাজ করে এমন ডিভাইস দেখুন।
এক্সটেনশন আর্কিটেকচার
নিচের ছবিতে ক্যামেরা এক্সটেনশন আর্কিটেকচার দেখানো হয়েছে।
CameraX অ্যাপ্লিকেশন CameraX এক্সটেনশন API-এর মাধ্যমে এক্সটেনশন ব্যবহার করতে পারে। CameraX Extensions API উপলভ্য এক্সটেনশন কোয়েরি করা, এক্সটেনশন ক্যামেরা সেশন কনফিগার করা এবং Camera Extensions OEM লাইব্রেরির সাথে যোগাযোগ করার মতো কাজগুলি ম্যানেজ করে। এটি আপনার অ্যাপ্লিকেশনকে নাইট, HDR, অটো, বোকেহ বা ফেস রিটাচ করার মতো ক্ষমতা ব্যবহার করার অনুমতি দেয়।
ইমেজ ক্যাপচার ও প্রিভিউয়ের জন্য এক্সটেনশন চালু করা
এক্সটেনশন API ব্যবহার করার আগে, ExtensionsManager#getInstanceAsync(Context, CameraProvider)
পদ্ধতি ব্যবহার করে
ExtensionsManager ইনস্ট্যান্স ফিরিয়ে আনুন। এটি আপনাকে এক্সটেনশনের উপলভ্যতা সংক্রান্ত তথ্য
কোয়েরি করার অনুমতি দেবে। তারপর এক্সটেনশন চালু করা CameraSelector ফিরিয়ে আনুন। CameraSelector এক্সটেনশন চালু থাকা অবস্থায় bindToLifecycle()
মেথড কল করার সময়,
এক্সটেনশন মোড ইমেজ ক্যাপচার ও প্রিভিউ ব্যবহারের ক্ষেত্রে প্রয়োগ করা হবে।
ইমেজ ক্যাপচার ও প্রিভিউ ব্যবহারের ক্ষেত্রে এক্সটেনশন প্রয়োগ করতে, নিম্নলিখিত কোড স্যাম্পেল দেখুন:
Kotlin
import androidx.camera.extensions.ExtensionMode import androidx.camera.extensions.ExtensionsManager override fun onCreate(savedInstanceState: Bundle?) { super.onCreate(savedInstanceState) val lifecycleOwner = this val cameraProviderFuture = ProcessCameraProvider.getInstance(applicationContext) cameraProviderFuture.addListener({ // Obtain an instance of a process camera provider // The camera provider provides access to the set of cameras associated with the device. // The camera obtained from the provider will be bound to the activity lifecycle. val cameraProvider = cameraProviderFuture.get() val extensionsManagerFuture = ExtensionsManager.getInstanceAsync(applicationContext, cameraProvider) extensionsManagerFuture.addListener({ // Obtain an instance of the extensions manager // The extensions manager enables a camera to use extension capabilities available on // the device. val extensionsManager = extensionsManagerFuture.get() // Select the camera val cameraSelector = CameraSelector.DEFAULT_BACK_CAMERA // Query if extension is available. // Not all devices will support extensions or might only support a subset of // extensions. if (extensionsManager.isExtensionAvailable(cameraSelector, ExtensionMode.NIGHT)) { // Unbind all use cases before enabling different extension modes. try { cameraProvider.unbindAll() // Retrieve a night extension enabled camera selector val nightCameraSelector = extensionsManager.getExtensionEnabledCameraSelector( cameraSelector, ExtensionMode.NIGHT ) // Bind image capture and preview use cases with the extension enabled camera // selector. val imageCapture = ImageCapture.Builder().build() val preview = Preview.Builder().build() // Connect the preview to receive the surface the camera outputs the frames // to. This will allow displaying the camera frames in either a TextureView // or SurfaceView. The SurfaceProvider can be obtained from the PreviewView. preview.setSurfaceProvider(surfaceProvider) // Returns an instance of the camera bound to the lifecycle // Use this camera object to control various operations with the camera // Example: flash, zoom, focus metering etc. val camera = cameraProvider.bindToLifecycle( lifecycleOwner, nightCameraSelector, imageCapture, preview ) } catch (e: Exception) { Log.e(TAG, "Use case binding failed", e) } } }, ContextCompat.getMainExecutor(this)) }, ContextCompat.getMainExecutor(this)) }
জাভা
import androidx.camera.extensions.ExtensionMode; import androidx.camera.extensions.ExtensionsManager; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); final LifecycleOwner lifecycleOwner = this; final ListenableFuturecameraProviderFuture = ProcessCameraProvider.getInstance(getApplicationContext()); cameraProviderFuture.addListener(() -> { try { // Obtain an instance of a process camera provider // The camera provider provides access to the set of cameras associated with the // device. The camera obtained from the provider will be bound to the activity // lifecycle. final ProcessCameraProvider cameraProvider = cameraProviderFuture.get(); final ListenableFuture extensionsManagerFuture = ExtensionsManager.getInstanceAsync(getApplicationContext(), cameraProvider); extensionsManagerFuture.addListener(() -> { // Obtain an instance of the extensions manager // The extensions manager enables a camera to use extension capabilities available // on the device. try { final ExtensionsManager extensionsManager = extensionsManagerFuture.get(); // Select the camera final CameraSelector cameraSelector = CameraSelector.DEFAULT_BACK_CAMERA; // Query if extension is available. // Not all devices will support extensions or might only support a subset of // extensions. if (extensionsManager.isExtensionAvailable( cameraSelector, ExtensionMode.NIGHT )) { // Unbind all use cases before enabling different extension modes. cameraProvider.unbindAll(); // Retrieve extension enabled camera selector final CameraSelector nightCameraSelector = extensionsManager .getExtensionEnabledCameraSelector(cameraSelector, ExtensionMode.NIGHT); // Bind image capture and preview use cases with the extension enabled camera // selector. final ImageCapture imageCapture = new ImageCapture.Builder().build(); final Preview preview = new Preview.Builder().build(); // Connect the preview to receive the surface the camera outputs the frames // to. This will allow displaying the camera frames in either a TextureView // or SurfaceView. The SurfaceProvider can be obtained from the PreviewView. preview.setSurfaceProvider(surfaceProvider); cameraProvider.bindToLifecycle( lifecycleOwner, nightCameraSelector, imageCapture, preview ); } } catch (ExecutionException | InterruptedException e) { throw new RuntimeException(e); } }, ContextCompat.getMainExecutor(this)); } catch (ExecutionException | InterruptedException e) { throw new RuntimeException(e); } }, ContextCompat.getMainExecutor(this)); }
এক্সটেনশন বন্ধ করুন
ভেন্ডর এক্সটেনশন বন্ধ করতে, সব ব্যবহারের কেস আনবাইন্ড করুন এবং সাধারণ ক্যামেরা সিলেক্টর দিয়ে ইমেজ ক্যাপচার
ও প্রিভিউ ব্যবহারের কেস আবার বাইন্ড করুন। যেমন, CameraSelector.DEFAULT_BACK_CAMERA ব্যবহার করে
ব্যাক ক্যামেরায় আবার বাইন্ড করুন।
ডিপেন্ডেন্সি
CameraX Extensions API, camera-extensions লাইব্রেরিতে প্রয়োগ করা হয়েছে।
এক্সটেনশনগুলি CameraX কোর মডিউলের (core, camera2,
lifecycle) উপর নির্ভর করে।
গ্ৰুভি
dependencies { def camerax_version = "1.2.0-rc01" implementation "androidx.camera:camera-core:${camerax_version}" implementation "androidx.camera:camera-camera2:${camerax_version}" implementation "androidx.camera:camera-lifecycle:${camerax_version}" //the CameraX Extensions library implementation "androidx.camera:camera-extensions:${camerax_version}" ... }
Kotlin
dependencies { val camerax_version = "1.2.0-rc01" implementation("androidx.camera:camera-core:${camerax_version}") implementation("androidx.camera:camera-camera2:${camerax_version}") implementation("androidx.camera:camera-lifecycle:${camerax_version}") // the CameraX Extensions library implementation("androidx.camera:camera-extensions:${camerax_version}") ... }
পুরনো API সরানো
1.0.0-alpha26-এ রিলিজ করা নতুন Extensions API-এর সাথে, আগস্ট ২০১৯-এ রিলিজ করা পুরনো
Extensions API এখন বন্ধ করা হয়েছে। 1.0.0-alpha28 ভার্সন থেকে শুরু করে, লাইব্রেরি থেকে পুরনো এক্সটেনশন API সরিয়ে দেওয়া হয়েছে। নতুন Extensions API ব্যবহার করা অ্যাপ্লিকেশনগুলিকে এখন অবশ্যই একটি
এক্সটেনশন-চালু করা CameraSelector
অর্জন করতে হবে এবং ব্যবহারের ক্ষেত্রে এটি ব্যবহার করতে হবে।
পুরনো Extensions API ব্যবহার করা অ্যাপ্লিকেশনগুলিকে নতুন Extensions API-তে মাইগ্রেট করতে হবে যাতে আসন্ন CameraX রিলিজের সাথে ভবিষ্যতের সামঞ্জস্য নিশ্চিত করা যায়।
অতিরিক্ত রিসোর্স
CameraX সম্পর্কে আরও জানতে, নিম্নলিখিত অতিরিক্ত রিসোর্স দেখুন।
কোডল্যাব
কোডের স্যাম্পেল
CameraX এক্সটেনশন স্যাম্পেল অ্যাপ
অন্যান্য রেফারেন্স
CameraX ভেন্ডর এক্সটেনশন যাচাইকরণ টুল