Android Question Erasing canvas object (aka circle) on a pinchandzoom image

foakgul

Member
Licensed User
Longtime User
Hi, this might have been discussed in different contexts but my question is how to erase a circle that is drawn on an image which is assigned to a pinchandzoom view:

B4X:
Dim im As ImageView
Dim pnz As PinchZoomAndMove
dim canvas1 as canvas

'load bitmap onto image
bmp = LoadBitmap(File.DirAssets,"example.bmp")
im.Initialize("")
im.Bitmap = bmp
im.Gravity = Gravity.FILL

'assign image to pinchzoom view
pnz.Initialize(im,"pnz",1,0.5,3,4,False)

'initialize canvas on image
canvas1.Initialize(im)

' this circle gets drawn
canvas1.DrawCircle(x,y,2dip,Colors.Red,False,2dip)

' how to remove this circle from image????

So i want to be able to erase this circle (might be another canvas object, line, rectangle etc) and draw it somewhere else on the image.

Thanks a lot!
 

foakgul

Member
Licensed User
Longtime User
Also, i tried
B4X:
canvas1.DrawCircle(x,y,2dip,Colors.transparent,False,2dip)
but it leaves behind a black circle.
 
Upvote 0

klaus

Expert
Licensed User
Longtime User
Once you have drawn something onto an image you cannot erase it.
You should either:
- replace the image by the original one.
- add a separate transparent Panel on top of the image where you draw the circle and to erase it drawi the circle transparent as you tried.
 
Upvote 0

foakgul

Member
Licensed User
Longtime User
Thanks Klaus. But I still want to be able to zoom in and out of the image (also pan) with the drawn circle so in a sense i want it to be part of the pinchzoom object. When the circle previously drawn is erased, the new circle can be drawn possibly at a different zoom level to a new location. Is this still possible with a transparent layer?
 
Upvote 0

foakgul

Member
Licensed User
Longtime User
Got it!

Needed to use getzoom property to scale x and y and radius for circle for a redraw.

Also, i'm using your first method: I'm replacing image every time!!

Thx!
 
Upvote 0
Cookies are required to use this site. You must accept them to continue using the site. Learn more…