CameraX, ऐसे एक्सटेंशन ऐक्सेस करने के लिए एक्सटेंशन एपीआई उपलब्ध कराता है जिन्हें डिवाइस बनाने वाली कंपनियां अलग-अलग Android डिवाइसों पर लागू करती हैं. इस्तेमाल किए जा सकने वाले एक्सटेंशन मोड की सूची देखने के लिए, कैमरा एक्सटेंशन देखें.
एक्सटेंशन का इस्तेमाल करने वाले डिवाइसों की सूची के लिए, काम करने वाले डिवाइस देखें.
एक्सटेंशन आर्किटेक्चर
नीचे दी गई इमेज में कैमरा एक्सटेंशन का आर्किटेक्चर दिखाया गया है.

CameraX ऐप्लिकेशन, CameraX एक्सटेंशन एपीआई की मदद से एक्सटेंशन का इस्तेमाल कर सकता है. कॉन्टेंट बनाने CameraX एक्सटेंशन API, उपलब्ध एक्सटेंशन के लिए क्वेरी करने को मैनेज करता है, ताकि एक्सटेंशन कैमरा सेशन और कैमरा एक्सटेंशन OEM से बातचीत करना लाइब्रेरी. इससे आपके ऐप्लिकेशन में नाइट, एचडीआर, ऑटो, बोकेह या चेहरे की फ़ोटो क्वालिटी में सुधार करने की सुविधा.
इमेज कैप्चर करने और उसकी झलक देखने के लिए, एक्सटेंशन चालू करें
एक्सटेंशन एपीआई का इस्तेमाल करने से पहले, ExtensionsManager
इंस्टेंस वापस पाएं
extensionsManager#getInstanceAsync(Context, CameraProvider) का इस्तेमाल करके
तरीका. इससे आपको एक्सटेंशन की उपलब्धता के बारे में क्वेरी करने की अनुमति मिलेगी
जानकारी. इसके बाद, चालू किया गया CameraSelector
एक्सटेंशन वापस पाएं. कॉन्टेंट बनाने
एक्सटेंशन मोड, इमेज कैप्चर करने और झलक देखने के मामलों में तब लागू होगा, जब
bindTolifecycle() को कॉल करके
CameraSelector
एक्सटेंशन वाला तरीका चालू किया गया.
इमेज कैप्चर करने और झलक देखने के इस्तेमाल के उदाहरणों के लिए, एक्सटेंशन लागू करने के लिए, यहां दिया गया कोड सैंपल देखें:
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 ListenableFuture
एक्सटेंशन बंद करें
वेंडर एक्सटेंशन बंद करने के लिए, इस्तेमाल के सभी उदाहरणों को बंद करें और इमेज कैप्चर को फिर से बाइंड करें
और सामान्य कैमरा सिलेक्टर की मदद से, इस्तेमाल के उदाहरणों की झलक देखें. उदाहरण के लिए,
CameraSelector.DEFAULT_BACK_CAMERA
का इस्तेमाल करके, पीछे वाला कैमरा इस्तेमाल करें.
डिपेंडेंसी
CameraX एक्सटेंशन एपीआई, 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}"
...
}
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}")
...
}
लेगसी एपीआई को हटाना
1.0.0-alpha26
में रिलीज़ हुए नए एक्सटेंशन एपीआई के साथ, लेगसी वर्शन
अगस्त 2019 में रिलीज़ किया गया एक्सटेंशन एपीआई अब काम नहीं करता. इससे शुरू हो रहा है
वर्शन 1.0.0-alpha28
है, तो लेगसी एक्सटेंशन एपीआई को
लाइब्रेरी. नए एक्सटेंशन एपीआई का इस्तेमाल करने वाले ऐप्लिकेशन को अब
CameraSelector
एक्सटेंशन चालू किया गया
और इसका इस्तेमाल, इस्तेमाल के उदाहरणों से लिंक करने के लिए करें.
लेगसी एक्सटेंशन एपीआई का इस्तेमाल करने वाले ऐप्लिकेशन को नए वर्शन पर माइग्रेट करना चाहिए एक्सटेंशन एपीआई, ताकि आने वाले समय में CameraX के साथ काम करने में आसानी हो रिलीज़.
अन्य संसाधन
CameraX के बारे में ज़्यादा जानने के लिए, यहां दिए गए अन्य संसाधन देखें.
कोडलैब (कोड बनाना सीखना)
कोड सैंपल
CameraX एक्सटेंशन का सैंपल ऐप्लिकेशन
अन्य संदर्भ
CameraX वेंडर एक्सटेंशन की पुष्टि करने वाला टूल