সেভ করা পৃষ্ঠা গুছিয়ে রাখতে 'সংগ্রহ' ব্যবহার করুন
আপনার পছন্দ অনুযায়ী কন্টেন্ট সেভ করুন ও সঠিক বিভাগে রাখুন।
এই পৃষ্ঠাটি বর্ণনা করে কিভাবে CameraX দিয়ে উচ্চ মানের ছবি ক্যাপচার করা যায়। আপনি ImageCapture ক্লাস এবং এর সাথে সম্পর্কিত পদ্ধতিগুলির সাথে এটি করেন।
মূল ধারণা
এই নথিতে আলোচনা করা প্রাথমিক ধারণাগুলি নিম্নরূপ:
স্টোরেজ পদ্ধতি : আপনি একটি ইন-মেমরি বাফার বা সরাসরি একটি ফাইলে ছবি ক্যাপচার করতে পারেন।
নির্বাহক :ImageCapture কলব্যাক এবং I/O অপারেশন পরিচালনার জন্য নির্বাহক ব্যবহার করে। আপনি ভাল কর্মক্ষমতা এবং নিয়ন্ত্রণের জন্য এই নির্বাহকদের কাস্টমাইজ করতে পারেন।
ক্যাপচার মোড : আপনি লেটেন্সি বা ইমেজ মানের জন্য অপ্টিমাইজ করতে ক্যাপচার মোড কনফিগার করতে পারেন।
স্টোরেজ পদ্ধতি
ImageCapture দিয়ে ছবি তোলার দুটি উপায় রয়েছে। তারা প্রত্যেকে ImageCapture.takePicture() এর ওভারলোড ব্যবহার করে :
এটি রিয়েল-টাইম ইমেজ প্রসেসিং বা বিশ্লেষণের জন্য উপযোগী।
নির্বাহক
আপনি যখন takePicture কল করেন, তখন আপনি একটি Executor এবং হয় একটি OnImageCapturedCallback বা OnImageSavedCallback ফাংশন পাস করেন। Executor কলব্যাক চালায় এবং যেকোন ফলাফল আইও পরিচালনা করে।
ছবি তুলুন
একটি ছবি তুলতে, আপনি ক্যামেরা সেট আপ করুন এবং তারপর takePicture কল করুন৷
আপনি ক্যামেরা কনফিগার করার পরে, একটি ছবি ক্যাপচার করতে takePicture() কল করুন। এই উদাহরণটি প্রদর্শন করে যে কীভাবে একটি ছবি ডিস্কে সংরক্ষণ করতে takePicture() ব্যবহার করতে হয়:
কোটলিন
funonClick(){valoutputFileOptions=ImageCapture.OutputFileOptions.Builder(File(...)).build()imageCapture.takePicture(outputFileOptions,cameraExecutor,object:ImageCapture.OnImageSavedCallback{overridefunonError(error:ImageCaptureException){// insert your code here.}overridefunonImageSaved(outputFileResults:ImageCapture.OutputFileResults){// insert your code here.}})}
জাভা
publicvoidonClick(){ImageCapture.OutputFileOptionsoutputFileOptions=newImageCapture.OutputFileOptions.Builder(newFile(...)).build();imageCapture.takePicture(outputFileOptions,cameraExecutor,newImageCapture.OnImageSavedCallback(){@OverridepublicvoidonImageSaved(ImageCapture.OutputFileResultsoutputFileResults){// insert your code here.}@OverridepublicvoidonError(ImageCaptureExceptionerror){// insert your code here.}});}
এই পৃষ্ঠার কন্টেন্ট ও কোডের নমুনাগুলি Content License-এ বর্ণিত লাইসেন্সের অধীনস্থ। Java এবং OpenJDK হল Oracle এবং/অথবা তার অ্যাফিলিয়েট সংস্থার রেজিস্টার্ড ট্রেডমার্ক।
2025-07-29 UTC-তে শেষবার আপডেট করা হয়েছে।
[null,null,["2025-07-29 UTC-তে শেষবার আপডেট করা হয়েছে।"],[],[],null,["# Capture an image\n\nThis page describes how to capture high-quality images with CameraX. You do so\nwith the [`ImageCapture`](/reference/androidx/camera/core/ImageCapture) class and its associated methods.\n| **Note:** This workflow accommodates the 3A features: auto-white-balance, auto-exposure, and auto-focus. It also supports basic manual camera controls.\n\nKey concepts\n------------\n\nThe following are the primary concepts discussed in this document:\n\n- **[Storage method](#capture):** You can capture images either to an in-memory buffer or directly to a file.\n- **[Executors](#executors):** `ImageCapture` uses executors for handling callbacks and I/O operations. You can customize these executors for better performance and control.\n- **[Capture Modes](/media/camera/camerax/take-photo/options):** You can configure the capture mode to optimize for either latency or image quality.\n\n### Storage method\n\nThere are two ways to capture images with\n`ImageCapture`. They each use an overload of `ImageCapture.takePicture()`:\n\n- **File:** Use [`takePicture(OutputFileOptions, Executor,\n OnImageSavedCallback)`](/reference/androidx/camera/core/ImageCapture#takePicture(androidx.camera.core.ImageCapture.OutputFileOptions,%20java.util.concurrent.Executor,%20androidx.camera.core.ImageCapture.OnImageSavedCallback)) to save the captured image directly to a file on\n disk.\n\n - This is the most common way to capture photos.\n- **In-Memory:** Use [`takePicture(Executor,\n OnImageCapturedCallback)`](/reference/androidx/camera/core/ImageCapture#takePicture(java.util.concurrent.Executor,%20androidx.camera.core.ImageCapture.OnImageCapturedCallback)) to receive an in-memory buffer of the captured\n image.\n\n - This is useful for real-time image processing or analysis.\n\n### Executors\n\nWhen you call `takePicture`, you pass an [`Executor`](/reference/java/util/concurrent/Executor) and either a\n`OnImageCapturedCallback` or `OnImageSavedCallback` function. The `Executor`\nruns the callback and handles any resulting IO.\n| **Note:** You can set the default executor for IO tasks with [`ImageCapture.Builder.setIoExecutor(Executor)`](/reference/androidx/camera/core/ImageCapture.Builder#setIoExecutor(java.util.concurrent.Executor)). If you don't set a default, CameraX uses to an internal IO executor.\n\nTake photo\n----------\n\nTo take a photo, you set up the camera and then call `takePicture`.\n\n### Set up the camera\n\nTo set up the camera, create a [`CameraProvider`](/media/camera/camerax/preview#get-provider). Then, create an\n`ImageCapture` object. Use [`ImageCapture.Builder()`](/reference/androidx/camera/core/ImageCapture.Builder): \n\n### Kotlin\n\n val imageCapture = ImageCapture.Builder()\n .setTargetRotation(view.display.rotation)\n .build()\n\n cameraProvider.bindToLifecycle(lifecycleOwner, cameraSelector, imageCapture, preview)\n\n### Java\n\n ImageCapture imageCapture =\n new ImageCapture.Builder()\n .setTargetRotation(view.getDisplay().getRotation())\n .build();\n\n cameraProvider.bindToLifecycle(lifecycleOwner, cameraSelector, imageCapture, preview);\n\n| **Note:** [`bindToLifecycle()`](/reference/androidx/camera/lifecycle/ProcessCameraProvider#bindToLifecycle(androidx.lifecycle.LifecycleOwner,%20androidx.camera.core.CameraSelector,%20androidx.camera.core.UseCase...)) returns a [`Camera`](/reference/androidx/camera/core/Camera) object. See the [Configuration options guide](/training/camerax/configuration#camera-output) for more on controlling camera output, such as zoom and exposure.\n\n### Take a picture\n\nAfter you configure the camera, call `takePicture()` to capture an image.\nThis example demonstrates how to use [`takePicture()`](/reference/androidx/camera/core/ImageCapture#takePicture(androidx.camera.core.ImageCapture.OutputFileOptions,%20java.util.concurrent.Executor,%20androidx.camera.core.ImageCapture.OnImageSavedCallback)) to save an image\nto disk: \n\n### Kotlin\n\n fun onClick() {\n val outputFileOptions = ImageCapture.OutputFileOptions.Builder(File(...)).build()\n imageCapture.takePicture(outputFileOptions, cameraExecutor,\n object : ImageCapture.OnImageSavedCallback {\n override fun onError(error: ImageCaptureException)\n {\n // insert your code here.\n }\n override fun onImageSaved(outputFileResults: ImageCapture.OutputFileResults) {\n // insert your code here.\n }\n })\n }\n\n### Java\n\n public void onClick() {\n ImageCapture.OutputFileOptions outputFileOptions =\n new ImageCapture.OutputFileOptions.Builder(new File(...)).build();\n imageCapture.takePicture(outputFileOptions, cameraExecutor,\n new ImageCapture.OnImageSavedCallback() {\n @Override\n public void onImageSaved(ImageCapture.OutputFileResults outputFileResults) {\n // insert your code here.\n }\n @Override\n public void onError(ImageCaptureException error) {\n // insert your code here.\n }\n }\n );\n }\n\nHere are the key points about this snippet:\n\n- The [`ImageCapture.OutputFileOptions`](/reference/androidx/camera/core/ImageCapture.OutputFileOptions) lets you configure save location and metadata.\n - Here, the `OutputFileOptions.Builder()` uses a `File` object to determine the save location.\n- The `takePicture()` function captures the image asynchronously using the provided options and executor.\n- The [`OnImageSavedCallback`](/reference/androidx/camera/core/ImageCapture#takePicture(androidx.camera.core.ImageCapture.OutputFileOptions,%20java.util.concurrent.Executor,%20androidx.camera.core.ImageCapture.OnImageSavedCallback)) provides callbacks for success and failure.\n - The `onImageSaved()` callback handles successful image capture and provides access to the [saved image results](/reference/androidx/camera/core/ImageCapture.OutputFileResults).\n - The `onError()` callback handles image capture errors.\n\nAdditional options\n------------------\n\nSee the [Configure for optimization, flash, and file format guide](/media/camera/camerax/take-photo/options) for extra\nways you can configure `ImageCapture`.\n\nFurther resources\n-----------------\n\nTo learn more about CameraX, consult the following resources:\n\n### Codelab\n\n\n- [Getting Started with CameraX](https://codelabs.developers.google.com/codelabs/camerax-getting-started)\n\n### Code sample\n\n- \n- [CameraX sample apps](https://github.com/android/camera-samples/)"]]