我正在尝试创建一个 Canvas 并使用以下代码在其上绘制位图:
Paint paint = new Paint();
InputStream is = assets.open("card_art" + File.separator + "texture.png");
Bitmap bitmap = BitmapFactory.decodeStream(is);
cardFrontBackingImageView = new SurfaceView(Order.getContext()).getHolder().lockCanvas();
if (cardFrontBackingImageView == null)
{
Log.e("Canvas creation", "Canvas is null");
}
cardFrontBackingImageView.drawBitmap(bitmap, null, frame, paint);
我遇到的问题是我在代码中检查的问题——lockCanvas() 始终返回 null。我或多或少地在学习过程中学习这一点,所以我对 SurfaceView、SurfaceHolder 或 Canvas 的了解不够,无法以某种方式说出我可能做错了什么;有什么建议吗?
最佳答案
来自doc :
The returned Canvas can be used to draw into the surface's bitmap. A null is returned if the surface has not been created or otherwise cannot be edited. You will usually need to implement Callback.surfaceCreated to find out when the Surface is available for use.
关于android - SurfaceHolder.lockCanvas() 返回 null,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13203437/