Drawing a bitmap in a canvas after calling setBitmap doesn't work
I'm drawing a bitmap in a canvas and i want to have the result in a new bitmap, but i still have a black screen as result. This is my code, part of the onDraw(Canvas canvas) method :
if (bitmapTemplate == null) {canvasBis = new Canvas();
bitmapTemplate = Bitmap.createBitmap(canvas.getWidth()+30,canvas.getHeight(),Bitmap.Config.ARGB_8888);
drawZones(canvasBis,bitmapTemplate);
}
bitmapRes = Bitmap.createBitmap(canvas.getWidth()+30,canvas.getHeight(),Bitmap.Config.ARGB_8888);
canvas.setBitmap(bitmapRes);
canvas.drawBitmap(bitmapTemplate, matrix, null);
My goal is to have a new bitmap (bitmapRes) by applying a matrix on an existing bitmap (bitmapTemplate). With this code i alway have a black screen, but when i remove the line canvas.setBitmap(bitmapRes) i have a result but not in a new bitmap. any ideas please ? Maybe transparency ? Thanks in advance.
drawZones draws some zones in bitmapTemplate.
You should try using the Canvas(Bitmap) constructor instead of the empty constructor. This sets the bitmap to the canvas for you.
链接地址: http://www.djcxy.com/p/63782.html上一篇: 将可绘制的资源图像转换为位图