android 如何裁剪imageProxy

0lvr5msh  于 2023-05-21  发布在  Android
关注(0)|答案(1)|浏览(152)

我想裁剪ImageProxy,为了分析数据只在预览边界.我尝试了很多东西,这里是我发现,我只是创建自定义视图覆盖,只包含ConstraintLayout和ImageView:

class ScannerOverlay @JvmOverloads constructor(
    context: Context,
    attrs: AttributeSet? = null,
    defStyleAttr: Int = 0
) : ConstraintLayout(context, attrs, defStyleAttr) {

    private var binding: ScannerOverlayBinding

    init {
        inflate(context, R.layout.scanner_overlay, this)
        binding = ScannerOverlayBinding.inflate(LayoutInflater.from(context))
    }

    val size: Size
        get() = Size(width, height)

    fun scanRect(): RectF {
        // binding.scannerOverlay
        // Here I want to return Rect by preview image
        // return RectF()
    }
}

我得到了xml布局

<?xml version="1.0" encoding="utf-8"?>
<androidx.constraintlayout.widget.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    android:layout_width="match_parent"
    android:layout_height="match_parent">

    <ImageView
        android:id="@+id/scannerOverlay"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_marginHorizontal="24dp"
        android:contentDescription="@null"
        android:src="@drawable/ic_scanner_target"
        app:layout_constraintBottom_toBottomOf="parent"
        app:layout_constraintEnd_toEndOf="parent"
        app:layout_constraintStart_toStartOf="parent"
        app:layout_constraintTop_toTopOf="parent" />

</androidx.constraintlayout.widget.ConstraintLayout>

在尺寸的情况下,它的方式很简单,但我找不到任何有用的例子ImageView的情况下

qv7cva1a

qv7cva1a1#

我也遇到过这样的要求。这一次,我发现这个博客很有帮助。https://medium.com/@sdptd20/exploring-ocr-capabilities-of-ml-kit-using-camera-x-9949633af0fe
如果有用的话,请留下评论。谢谢你。

相关问题