문제

I'm trying to create a canvas and draw a bitmap to it using the following code:

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);

The problem that I'm running into is the one that I'm checking for in the code--lockCanvas() is consistently returning null. I'm more or less learning this as I go along, so I don't know enough about the SurfaceView, SurfaceHolder, or Canvas to say one way or another what I might be doing wrong; any suggestions?

도움이 되었습니까?

해결책

From the 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.

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top