gpt4 book ai didi

Android - 在 SurfaceView 上绘图未出现

转载 作者:太空宇宙 更新时间:2023-11-03 12:33:04 27 4
gpt4 key购买 nike

I simply want to draw a square over the camera preview on my android app. The camera preview displays on a SurfaceView, and from my reading online it seems that the best way to accomplish this was to place another SurfaceView over the one the camera feed displays on and draw on that. So I added this and also added some code but it isn't working, I see the camera feed no problem but the square never gets drawn. Just wondering if anybody had any thoughts on what I have missed. My DrawFocusRect function gets called, its just my rectangle never appears.

布局 xml 文件中的表面 View

     <RelativeLayout
android:layout_width="match_parent"
android:layout_height="150dp"
android:orientation="vertical" >

<SurfaceView
android:id="@+id/full_colour"
android:layout_width="fill_parent"
android:layout_height="match_parent" />

<SurfaceView
android:layout_alignParentTop="true"
android:id="@+id/TransparentView"
android:layout_width="match_parent"
android:layout_height="match_parent" />

</RelativeLayout>

我的绘图代码,从 onPreviewFrame 调用

private static void DrawFocusRect()
{
int hWidth = transparentView.getWidth();
int hHeight = transparentView.getHeight();

float f = (float) 0.5;
float rLeft = (float) Math.floor(((1-f)/2)*hWidth);
float rRight = (float) Math.floor((((1-f)/2)+f)*hWidth);
float rTop = (float) Math.floor(((1-f)/2)*hHeight);
float rBottom = (float) Math.floor((((1-f)/2)+f)*hHeight);

canvas = holderTranspaernt.lockCanvas();

canvas.drawColor(Color.GREEN, Mode.CLEAR);
//border's properties
paint = new Paint();
paint.setStyle(Paint.Style.STROKE);
paint.setColor(Color.YELLOW);
paint.setStrokeWidth(3);
canvas.drawRect(rLeft, rTop, rRight, rBottom, paint);

holderTranspaernt.unlockCanvasAndPost(canvas);
}

最佳答案

You need to set zOrder in order to handle ordering of the view drawn on SurfaceView.

尝试设置 setZOrderOnTop您的观点:

transparentView.setZOrderOnTop(true);

希望能帮到你

关于Android - 在 SurfaceView 上绘图未出现,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/27705692/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com