【发布时间】:2015-03-12 10:37:06
【问题描述】:
我很难绕过surfaceview的角落。我正在使用 MjpegView (继承自surfaceview的自定义视图。 我已经尝试过这个解决方案: 1)用圆角自定义drawable设置背景 2) 看完这篇文章http://androidtutorialsandtips.blogspot.co.il/2012/01/overriding-ondraw-method-in-surfaceview.html 我不确定如何实现圆角,因为我已经实现了一个锁定画布的线程。
while (mRun)
{
if (surfaceDone)
{
try
{
c = mSurfaceHolder.lockCanvas();
synchronized (mSurfaceHolder)
{
try
{
if (mIn != null)
{
Bitmap bm = mIn.readMjpegFrame();
destRect = destRect(bm.getWidth(), bm.getHeight());
if (streamHeight == -1 && streamWidth == -1)
{
streamWidth = bm.getWidth();
streamHeight = bm.getHeight();
}
c.drawColor(Color.BLACK);
c.drawBitmap(bm, null, destRect, p);
if (showFps)
{
p.setXfermode(mode);
if (ovl != null)
{
height = ((ovlPos & 1) == 1) ? destRect.top : destRect.bottom - ovl.getHeight();
width = ((ovlPos & 8) == 8) ? destRect.left : destRect.right - ovl.getWidth();
c.drawBitmap(ovl, width, height, null);
}
p.setXfermode(null);
frameCounter++;
if ((System.currentTimeMillis() - start) >= 1000)
{
fps = String.valueOf(frameCounter) + "fps";
frameCounter = 0;
start = System.currentTimeMillis();
ovl = makeFpsOverlay(overlayPaint, fps);
}
}
}
}
catch (IOException e)
{
}
}
}
finally
{
if (c != null) mSurfaceHolder.unlockCanvasAndPost(c);
}
}
}
【问题讨论】:
-
你有什么问题?
-
我无法绕过surfaceview的角落
-
什么是模式?为什么你设置它但从不使用它?你的代码的结果是什么?
-
我正在使用这个视图code.google.com/p/android-camera-axis/source/browse/trunk/…。结果很简单,表面视图有角,我需要将它们移除。我尝试更改表面视图的背景,但它不起作用
-
FWIW,任何建议覆盖 SurfaceView 的
onDraw()的方法都可能是错误的。 SurfaceView 表面不是 View 层次结构的一部分,不应与之绑定。请记住,surface 位于一个单独的层上,位于所有 View UI 之后,并且与无效/刷新周期无关,事情会更有意义。如下面的回答中所述,将不透明的圆角图像放在叠加层上,是做你想做的最简单的方法。
标签: android stream surfaceview