gpt4 book ai didi

android - SurfaceHolder.lockCanvas() 返回 null

转载 作者:搜寻专家 更新时间:2023-11-01 09:04:08 60 4
gpt4 key购买 nike

我正在尝试创建一个 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/

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