相关疑难解决方法(0)

如何将android.media.Image转换为位图对象?

在android中,我从这里获得了一个Image对象https://inducesmile.com/android/android-camera2-api-example-tutorial/这个相机教程.但是我现在想要循环显示像素值,是否有人知道我该怎么做?我是否需要将其转换为其他内容,我该怎么做?

谢谢

android image

17
推荐指数
2
解决办法
2万
查看次数

CameraX:将照片捕捉为位图

我正在试验 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)

android image-capture bitmap kotlin android-camerax

7
推荐指数
1
解决办法
3404
查看次数

将 CameraX 捕获的 ImageProxy 转换为位图

我正在使用 CameraX 并且很难将捕获的 ImageProxy 转换为位图。经过搜索和尝试,我制定了一个解决方案。后来我发现它不是最佳的,所以我改变了设计。这迫使我放弃工作时间。

由于我(或其他人)将来可能需要它,因此我决定将其作为问题发布在这里并发布和回答以供参考和审查。如果您有更好的答案,请随时添加更好的答案。

相关代码是:

class ImagePickerActivity : AppCompatActivity() {
    private var width = 325
    private var height = 205

    @RequiresApi(Build.VERSION_CODES.LOLLIPOP)
    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
        setContentView(R.layout.activity_image_picker)

        view_finder.post { startCamera() }
    }

    @RequiresApi(Build.VERSION_CODES.LOLLIPOP)
    private fun startCamera() {
        // Create configuration object for the viewfinder use case
        val previewConfig = PreviewConfig.Builder().apply {
            setTargetAspectRatio(Rational(1, 1))
            //setTargetResolution(Size(width, height))
            setLensFacing(CameraX.LensFacing.BACK)
            setTargetAspectRatio(Rational(width, height))
        }.build()

        }

        // Create configuration object for the image capture use case
        val imageCaptureConfig = ImageCaptureConfig.Builder()
            .apply {
                setTargetAspectRatio(Rational(1, …
Run Code Online (Sandbox Code Playgroud)

android android-camerax

6
推荐指数
4
解决办法
5898
查看次数

CameraX 图像拍照慢

我正在使用 CameraX

这是我的图像捕获:

 mImageCapture = ImageCapture.Builder()
            .setCaptureMode(ImageCapture.CAPTURE_MODE_MINIMIZE_LATENCY)
            .setTargetAspectRatio(screenAspectRatio)
            .build()
Run Code Online (Sandbox Code Playgroud)

图像捕捉监听器:

mImageCapture.takePicture(
                executor!!,
                object : ImageCapture.OnImageCapturedCallback() {


                    override fun onCaptureSuccess(image: ImageProxy) {
                        Log.d("AAAA", "Success")

                            val rotatedBitmap = bitmapHelper.rotateImage(
                                bitmapHelper.imageToBitmap(image = image.image!!),
                                image.imageInfo.rotationDegrees.toFloat()
                            )

                            runOnUiThread {
                                mImageView.setImageBitmap(rotatedBitmap)
                            }

                    }

                    override fun onError(
                        imageCaptureError: Int,
                        message: String,
                        cause: Throwable?
                    ) {
                        2
                        super.onError(imageCaptureError, message, cause)
                    }
                })
Run Code Online (Sandbox Code Playgroud)

当我调用takePicture应用程序冻结时,仅在 3-4 秒后 onCaptureSuccess 调用

我怎样才能使这个过程更快?

android android-camera android-camerax

6
推荐指数
1
解决办法
1860
查看次数

如何让 CameraX 预览在拍照时冻结?

我的自定义 CameraX 流程如下:

  • 打开相机预览(实时)
  • 点击按钮拍照
  • 单击该按钮时有一个过程(将路径转换为位图、旋转图像、自动裁剪图像、保存到设备中)
  • 运行所有进程并成功后,将图像发送到其他Fragment并将其显示为glide

问题是何时running all the process (in step 3)有 adelayed 2 seconds并且相机预览静止livenot freezelock)。怎么做camera preview freeze or lock when running the process

这是我在 Camera X 中运行相机预览的代码:

class CameraFragment : Fragment() {

        override fun onCreateView(
            inflater: LayoutInflater, container: ViewGroup?,
            savedInstanceState: Bundle?
        ): View? {
            // Inflate the layout for this fragment
            return inflater.inflate(R.layout.fragment_camera, container, false)
        }

        override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
            super.onViewCreated(view, savedInstanceState) …
Run Code Online (Sandbox Code Playgroud)

kotlin android-camerax

5
推荐指数
1
解决办法
6343
查看次数