draw line on panel background image

selvamurali

Active Member
Licensed User
Longtime User
dear team

i used the following code to draw line on panel background image

Sub Activity_Touch (Action As Int, X As Float, Y As Float)
pnlTest.Color=Colors.Transparent
cvsTest.Initialize(pnlTest)
cvsTest.DrawLine(x1,y1-pnlTest.Top,x2,y2-pnlTest.Top,Colors.Red,LineWidth)
pnlTest.Invalidate
End sub

in the above code if i use colors.transparent line drawed correctly. but image hide.

so if i remove that line line image showed and line drawed multiple or bended line .

what wrong with my code help me.

thanks in advance

sorry for my english
 

klaus

Expert
Licensed User
Longtime User
Attached you have a small test program.
With the Draw button a line and a circle are drawn onto the image.
With the Erase button the original image is reloaded 'erasing' the drawing.
Touching the screen you can draw 'rubber banding' lines.
For this a second transparent Panel is added, the rubber banding lines are drawn onto this panel and the final line is drawn onto the image when Action is ACTION_UP.

Best regards.
 

Attachments

  • DrawPanel.zip
    34.6 KB · Views: 1,362
Upvote 0

selvamurali

Active Member
Licensed User
Longtime User
Very nice example

Thanks Klaus
That was an nice example.

and also i want to erase selected part of line in the canvas . is it possible?

It really very helpfull for my project .
 
Upvote 0

klaus

Expert
Licensed User
Longtime User
and also i want to erase selected part of line in the canvas . is it possible?
No, because on the bitmap the original pixel colors are replaced by the new color.
What you could do is to save the last bitmaps and call those back. But this could become a memory problem.
I had used this in a Basic4PPC Icon editor program, I memorized the last three screens.

Best regards.
 
Upvote 0

Xardoz

Member
Licensed User
Longtime User
I have a panel with buttons on it

I want a horizontal line between the rows as a visual seperator

Not sure if it matters, I am using the AHViewPageFixer control
 
Upvote 0

Xardoz

Member
Licensed User
Longtime User
Not sure how to do this, sorry to sound dense...

B4X:
Dim pan As Panel
    pan = CreatePanel("Times" )
        container.AddPage(pan, "Times")
       
        cvsBackground.Initialize(pan.Background)
        cvsBackground.DrawLine(10dip, 50dip, 150dip, 100dip, Colors.Black, 5dip)
 
Upvote 0

Xardoz

Member
Licensed User
Longtime User
Thank you for the help
It is based on the example for the AHViewPagerFixer Demo

When I try your suggestion I get:
 
Last edited:
Upvote 0

klaus

Expert
Licensed User
Longtime User
Instead of :
B4X:
cvsBackground.Initialize(pan)
cvsBackground.DrawLine(10dip, 50dip, 150dip, 100dip, Colors.Black, 5dip)
Use this, you need to adapt the values to your needs :
B4X:
Dim pnl As Panel
pnl.Initialize("")
pnl.Color = Colors.Black
pan.AddView(pnl, 10dip, 42dip, 175dip, 3dip)
In your case the panel background is a ColorDrawable and not a BitmapDrawable.

You must use dip values for the positions and dimensions of Views !!!
 
Upvote 0

Xardoz

Member
Licensed User
Longtime User
THANK YOU!

Got it!

Make a panel to look like a line on top of the existing panel.
 
Last edited:
Upvote 0
Cookies are required to use this site. You must accept them to continue using the site. Learn more…