Android Question Clip / Crop with bitmapcreator ?

Martin D.

Member
Licensed User
Hi, is there a way to clip / crop with bitmapcreator ? Similar to canvas.ClipPath / canvas.RemoveClip. I would like to try using BitmapCreator instead of B4XCanvas, I'm trying to maximize performance gains.
 

Erel

Administrator
Staff member
Licensed User
Hi, is there a way to clip / crop with bitmapcreator ?
Yes. It is done by creating a BCBrush from a BitmapCreator or a Bitmap and then drawing using that brush.

Relevant example:


And:
 

Martin D.

Member
Licensed User
I tested it (BCBrush/DrawPath2), however drawing to a panel using B4XCanvas yielded 4-5x better time results than setting the panel's BG image with BC (DrawPath with BCBrush) after drawing to the bitmap initialized with BC.
100% of the code is the same except drawing so I conclude that currently, B4XCanvas draws faster than BC, at least when clipping/cropping from a path is required. However I may be wrong for some unknown reason :)

Thank you all, always good support, extremely appreciated.
 

sorex

Expert
Licensed User
wasn't B4X canvas based on bitmap creator for B4A/Android?

maybe Erel's predefined routines do it right and you're not? ;)
 

Martin D.

Member
Licensed User
Currently I do this 40 times :
Create a BCBrush (small square terrain image) and draw on a large bitmap according to a hexagon path...

Should I do the opposite ?

Create one transparent BCBrush, draw on each square terrain image according to an inverted path of a hexagon, then draw each bitmap on the main bitmap ?

I also realize that in this case I could use the same Path values for each terrain image instead of calculating/storing/using a path for each tile's location on the large bitmap. However the performance gain would be close to non-existant while drawing.

I think I have better ideas at work than at home. Is this good for my project ? ;)
 
Last edited:

Erel

Administrator
Staff member
Licensed User
wasn't B4X canvas based on bitmap creator for B4A/Android?
No. B4XCanvas = Canvas

BitmapCreator is not faster than Canvas in all cases. In many cases it will be slower.
It is the fastest way if you want to manipulate every pixel of the image. For example if you want to change the image brightness.
It is also faster with XUI2D which is based on BitmapCreator and by drawing with BC instead of Canvas you don't need to make slow conversions.

I think I have better ideas at work than at home. Is this good for my project ?
It will be easier to help if you create a small project with the drawing code.
 
Top