【发布时间】:2013-06-08 18:20:13
【问题描述】:
我正在尝试使用android.graphics.Picture 来加快我的应用程序所做的一些绘图。但是,当我尝试重放它时,什么也没有发生,就好像Picture 根本没有被绘制或者好像它没有记录任何东西。
这是我的绘图代码;为简单起见,我只是将所有内容移到了我的 View 的 onDraw 方法中。
@Override
protected void onDraw(Canvas canvas) {
super.onDraw(canvas);
canvas.drawColor(Color.RED);
Picture p = new Picture();
Paint paint = new Paint();
paint.setColor(Color.BLACK);
paint.setStyle(Style.STROKE);
Canvas c = p.beginRecording(100, 100);
c.drawColor(Color.WHITE);
c.drawLine(0, 0, 100, 100, paint);
p.endRecording();
p.draw(canvas);
canvas.drawPicture(p);
}
有了这个,我得到的只是一个完全红色的背景,没有别的;线条和Picture 的白色背景都没有出现。
然后我尝试了http://www.java2s.com/Code/Android/2D-Graphics/DrawPicture.htm 上发布的示例代码,但也无济于事:没有任何显示,我得到的只是白色背景。
这发生在我的 Galaxy S2 (Android 4.1.2) 和模拟器 (4.2.2) 上。
【问题讨论】: