Koleksiyonlar ile düzeninizi koruyun
İçeriği tercihlerinize göre kaydedin ve kategorilere ayırın.
Bu sayfada, CameraX ile yüksek kaliteli resimlerin nasıl çekileceği açıklanmaktadır. Bunu ImageCapture sınıfı ve ilişkili yöntemleriyle yaparsınız.
Temel kavramlar
Bu dokümanda ele alınan temel kavramlar şunlardır:
Depolama yöntemi: Resimleri, bellekteki bir arabelleğe veya doğrudan bir dosyaya kaydedebilirsiniz.
Yürütücüler:ImageCapture, geri çağırma ve G/Ç işlemlerini işlemek için yürütücüler kullanır. Daha iyi performans ve kontrol için bu yürütücüleri özelleştirebilirsiniz.
Kamera modları: Kamera modunu, gecikmeyi veya görüntü kalitesini optimize edecek şekilde yapılandırabilirsiniz.
Depolama yöntemi
ImageCapture ile resim çekmenin iki yolu vardır. Her biri ImageCapture.takePicture() aşırı yüklemesini kullanıyor:
Bu, gerçek zamanlı görüntü işleme veya analiz için yararlıdır.
Vasiyet tenfiz memurları
takePicture işlevini çağırdığınızda bir Executor ve OnImageCapturedCallback veya OnImageSavedCallback işlevi iletirsiniz. Executor, geri çağırma işlevini çalıştırır ve ortaya çıkan tüm G/Ç işlemlerini yönetir.
Fotoğraf çek
Fotoğraf çekmek için kamerayı ayarladıktan sonra takePicture numaralı telefonu arayın.
Kamerayı yapılandırdıktan sonra resim çekmek için takePicture() tuşuna basın.
Bu örnekte, bir resmi diske kaydetmek için takePicture() işlevinin nasıl kullanılacağı gösterilmektedir:
Kotlin
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.}})}
Java
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.}});}
Bu sayfadaki içerik ve kod örnekleri, İçerik Lisansı sayfasında açıklanan lisanslara tabidir. Java ve OpenJDK, Oracle ve/veya satış ortaklarının tescilli ticari markasıdır.
Son güncelleme tarihi: 2025-07-26 UTC.
[null,null,["Son güncelleme tarihi: 2025-07-26 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/)"]]