我正在试验 Google 的CameraX示例应用程序(CameraXBasic,可以在 Github 上找到),并希望将图像捕获为位图,以便能够在保存图像之前对图像进行一些修改。有没有人有关于如何实现这一目标的建议?
请参阅下面的谷歌原始代码来捕获和保存图像:
// Listener for button used to capture photo
controls.findViewById<ImageButton>(R.id.camera_capture_button).setOnClickListener {
// Get a stable reference of the modifiable image capture use case
imageCapture?.let { imageCapture ->
// Create output file to hold the image
val photoFile = createFile(outputDirectory, FILENAME, PHOTO_EXTENSION)
// Create output options object which contains file + metadata
val outputOptions = ImageCapture.OutputFileOptions.Builder(photoFile)
.build()
// Setup image capture listener which is triggered after photo has been taken
imageCapture.takePicture(
outputOptions, cameraExecutor, object …Run Code Online (Sandbox Code Playgroud) 我最近将我的应用程序切换到范围存储。但是,我注意到,当我从应用程序内共享图像(通过 Intent)时,GPS 位置数据将从图像的 Exif 元数据中删除。我知道范围存储对访问图像的 Exif 位置数据有一些限制,并且我知道该权限<uses-permission android:name="android.permission.ACCESS_MEDIA_LOCATION" />,但是添加此权限在共享图像时似乎没有任何效果。知道如何通过 Intent 共享图像,同时保留图像 Exif 数据中的位置数据吗?
这是我的代码:
val imageUri = mediaList[photo_view_pager.currentItem].uri
val intent = Intent().apply {
val mediaType = MimeTypeMap.getSingleton()
.getMimeTypeFromExtension("jpg")
putExtra(Intent.EXTRA_STREAM, imageUri)
type = mediaType
action = Intent.ACTION_SEND
flags = Intent.FLAG_GRANT_READ_URI_PERMISSION
}
startActivity(Intent.createChooser(intent, getString(R.string.share_hint)))
Run Code Online (Sandbox Code Playgroud)
预先非常感谢您的帮助!
android geolocation mediastore android-intent scoped-storage