用户绘图未显示在画布上
我有这样的 XML 布局:
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="match_parent"
>
<com.somedomain.drawings.DrawingSurface
android:layout_width="fill_parent"
android:layout_height="200dip"
android:id="@+id/drawingSurface"
android:background="@drawable/bg2"/>
<LinearLayout
android:orientation="horizontal"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true" >
<Button
android:layout_height="wrap_content"
android:layout_width="wrap_content"
android:text="OK"
android:onClick="onClick"
android:id="@+id/colorGreenBtn" />
</LinearLayout>
</RelativeLayout>
当我尝试在 DrawingSurface 上绘图时,绘图未显示。但画布的背景图像正在显示。当我保存它时,绘图将显示在输出上。
当我删除 DrawingSurface 的背景图像并尝试绘制它时,它正在显示。
我想当用户在带有背景图像的画布上绘图时显示绘图。有什么想法吗?非常感谢您的帮助! :)
更新:这是我的绘图代码
@Override
public void run() {
Canvas canvas = null;
while (_run){
if(isDrawing == true){
try{
canvas = mSurfaceHolder.lockCanvas(null);
if(mBitmap == null){
mBitmap = Bitmap.createBitmap (1, 1, Bitmap.Config.ARGB_8888);
}
final Canvas c = new Canvas (mBitmap);
c.drawColor(0, PorterDuff.Mode.CLEAR);
canvas.drawColor(0, PorterDuff.Mode.CLEAR);
canvas.drawColor(0x00000000);
commandManager.executeAll(c,previewDoneHandler);
previewPath.draw(c);
canvas.drawBitmap (mBitmap, 0, 0,null);
} finally {
mSurfaceHolder.unlockCanvasAndPost(canvas);
}
}
}
}
I have an XML layout like this:
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="match_parent"
>
<com.somedomain.drawings.DrawingSurface
android:layout_width="fill_parent"
android:layout_height="200dip"
android:id="@+id/drawingSurface"
android:background="@drawable/bg2"/>
<LinearLayout
android:orientation="horizontal"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true" >
<Button
android:layout_height="wrap_content"
android:layout_width="wrap_content"
android:text="OK"
android:onClick="onClick"
android:id="@+id/colorGreenBtn" />
</LinearLayout>
</RelativeLayout>
When I'm trying to draw on the DrawingSurface, the drawing isn't showing. But the background image of the canvas is showing. And when I save it, the drawing is showing on the output.
When I removed the background image of the DrawingSurface and try to draw to it, it is showing.
I want to show the drawing when the user draws on the canvas with the background image. Any ideas? Thanks a lot for any help! :)
Update: Here's my drawing code
@Override
public void run() {
Canvas canvas = null;
while (_run){
if(isDrawing == true){
try{
canvas = mSurfaceHolder.lockCanvas(null);
if(mBitmap == null){
mBitmap = Bitmap.createBitmap (1, 1, Bitmap.Config.ARGB_8888);
}
final Canvas c = new Canvas (mBitmap);
c.drawColor(0, PorterDuff.Mode.CLEAR);
canvas.drawColor(0, PorterDuff.Mode.CLEAR);
canvas.drawColor(0x00000000);
commandManager.executeAll(c,previewDoneHandler);
previewPath.draw(c);
canvas.drawBitmap (mBitmap, 0, 0,null);
} finally {
mSurfaceHolder.unlockCanvasAndPost(canvas);
}
}
}
}
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
可以尝试以下几件事:
1)将 ImageView 放在 XML 中的 drawSurface 之前,并将 bg 放入 ImageView 中。
我知道 SurfaceView 与其他视图不同,但你可以尝试一下。
2)也许您可以在绘图线程启动之前将背景绘制到画布上。
canvas.drawBitmap() 可能是您想要使用的。
Couple things to try:
1) put the ImageView before the drawSurface in XML, and put the bg into the ImageView.
I know the surfaceView is different than other view, but you could try out.
2) Maybe you could draw the bg onto the canvas first the drawing thread started.
canvas.drawBitmap() could be the one you wanna use.