In my Android paint application i am going to paint on the canvas.
But some times I have Image before that paint. At that time My paint become slow. Where is the Problem ??
The Code that only paint on Canvas:
@Override
protected void onDraw(Canvas canvas) {
//canvas.drawColor(0, PorterDuff.Mode.CLEAR);
// set the Canvas Color
canvas.drawColor(canvasColor); // edited
canvas.drawBitmap(mBitmap, 0, 0, mBitmapPaint);
canvas.drawPath(mPath, mPaint);
}
And the Code that get image as a Background is:
@Override
protected void onDraw(Canvas canvas) {
//canvas.drawColor(0, PorterDuff.Mode.CLEAR);
// set the Canvas Color
canvas.drawColor(canvasColor); // edited
if(!(imagePath==null))
{
Bitmap tempBitmap = BitmapFactory.decodeFile(imagePath); // from the gallery
photoBitmap = Bitmap.createScaledBitmap(tempBitmap, display.getWidth(), display.getHeight(), true);
}
if(!(imagePath==null))
{
canvas.drawBitmap (photoBitmap,0, 0, null);
}
canvas.drawBitmap(mBitmap, 0, 0, mBitmapPaint);
canvas.drawPath(mPath, mPaint);
}
Now i dont know why my paint become slow while i am paint on the canvas and if there is image as background.
Please help me in this.
Thanks.
Your application might getting slow due to this line Bitmap tempBitmap = BitmapFactory.decodeFile(imagePath); in your onDraw function. If you are changing bitmaps at every instance then you should declare it outside onDraw at just assign it new Bitmap and if you are not changing it then just initialize and assign object it at start and in onDraw just draw it in canvas.