如何在onImageAvailable方法中获取覆盖在TextureView上的CustomView位图点

时间:2018-08-09 12:28:47

标签: android android-camera2

我正在使用camera2 API。 我想用CustomView方法在Bitmap上覆盖textureView onImageAvailable点。

  

它是fragment_camera.xml。

<FrameLayout
    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">

    <com.tzutalin.dlibtest.AutoFitTextureView
        android:id="@+id/texture"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignParentStart="true"
        android:layout_alignParentTop="true"/>

   <RelativeLayout
        android:id="@+id/view"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:background="@android:color/transparent"/>

   </FrameLayout>
  

其CameraFragment.java。

@Override
public void onViewCreated(final View view, final Bundle savedInstanceState) {
    Dlog.d("onViewCreated");
    textureView = (AutoFitTextureView) view.findViewById(R.id.texture);
    surfaceView = (RelativeLayout)view.findViewById(R.id.view);
    eyeOverlayView = new CustomView(this);
    surfaceView.addView(eyeOverlayView);
}
  

其CustomView.java

@Override
protected void onDraw(Canvas canvas) {
    Dlog.d("onDraw");
    super.onDraw(canvas);
    setAspectRatio(canvas.getWidth(), canvas.getHeight());
    canvas.drawBitmap(mBitmap, mStartRightX, mStartRightY, null);
    canvas.drawBitmap(mBitmap, mStartLeftX, mStartLeftY, null);
}
  

其onImageAvailable方法。

@Override
public void onImageAvailable(final ImageReader reader) {

    image = reader.acquireLatestImage();

    if (image == null) {
        return;
    }
    if (mIsComputing) {
        image.close();
        return;
    }
    mIsComputing = true;

    final Plane[] planes = image.getPlanes();
    Log.i(TAG, String.format("image size (%d,%d)", image.getWidth(), image.getHeight()));

    if (mPreviewWdith != image.getWidth() || mPreviewHeight != image.getHeight()) {
        mPreviewWdith = image.getWidth();
        mPreviewHeight = image.getHeight();

        Log.i(TAG, String.format("Preview size (%d,%d)", mPreviewWdith, mPreviewHeight));
        mRGBBytes = new int[mPreviewWdith * mPreviewHeight];
        mRGBframeBitmap = Bitmap.createBitmap(mPreviewWdith, mPreviewHeight, Config.ARGB_8888);
    }

    mEyeOverlayView = eyeOverlayView;

    // I want to compare mEyeOverlayView.StartRightX, mEyeOverlayView.StartRightY to Specific point in mRGBframeBitmap
    // I know Specific point in mRGBframeBitmap. But it doesn't match the scale.
    // it is CustomView Bitmap scale on AutoFitTextureView and mRGBframeBitmap scale in onImageAvailable
}

我想将mEyeOverlayView.StartRightXmEyeOverlayView.StartRightYmRGBframeBitmap中的特定点进行比较。

我知道`mRGBframeBitmap中的特定点。但这与规模不符。

这是CustomView上的AutoFitTextureView位图比例,mRGBframeBitmap上是onImageAvailable比例。

0 个答案:

没有答案