语言

Menu
Sites
Language
Performance issue drawing on Canvas

I have a native game, in which I draw several bitmaps on form's canvas.
The problem is that if I draw background bitmap on whole canvas it slows down drawing process a lot.

I do it in onDraw method of my game form:

result GameForm::OnDraw() {
    result r = E_SUCCESS;
    pCanvas->SetBackgroundColor(*backgroundColor);
    pCanvas->Clear(*rect);

    //this increases time of drawing from about 25ms to 50ms
    //  r = pCanvas->DrawBitmap(Rectangle(0, 0, this->GetWidth(), this->GetHeight()), *pBackgroundBitmap);

    //drawing some (up to 60-80) small bitmaps on pCanvas
    pLevel->draw(pCanvas);

    return r;
}

I decode Images with BITMAP_PIXEL_FORMAT_ARGB8888 option.

I also tried to add a screen-size Label with background Bitmap, but it only got worse.

Is there any way to draw background bitmap more efficiently without using openGL?

响应

5 回复

I created painting app and noticed that drawing bitmap is slow inside OnDraw. So to improve the speed of painting I could not find any solution but to create Draw method similar to OnDraw and use a timer to call it ever x milliseconds instead of calling it on every touch event.

This improved the speed of painting becauseI reduced the calls to DrawBitmap which returns several errors in the log ...these errors are internal checks and don't effect the app but slow it.

However, this trick may not work for games.

Michał Karpiuk

I am already using timer to invode redrawing.  What methods do you use to refresh screen after repainting canvas?

I guess in the end onDraw() is going to be invoked anyway.

I ported the app from bada os and painting there was smoother. I don't override OnDraw now .. just DrawCanvas() method with similar code

Get form's Canvas -> Clear -> Draw -> Show. this method DrawCanvas is called when timer expires every 50-100 milliseconds instead of call OnDraw every touch moved event by calling OnDraw()

It is not perfect solution and not even happy with it but better than before. There is delay in updating the canvas but does not feel slow.. I don't know if it good for games!

If anyone else found a solution, then I will recode my app as well.

 

 

Chintan Gandhi

Hi Nour,

Even I have called Draw() function which recursively calls the child function OnDraw() on timer expired and that redraws the entire screen of my game app.

I personally feel its the best way.

:)

Thanks.

Good to know it works for games :)