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
 
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

Upvote 0
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
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
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
Not sure how to do this, sorry to sound dense...

Code: Copy
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
Thank you for the help
It is based on the example for the AHViewPagerFixer Demo

When I try your suggestion I get:
LogCat connected to: 0146DE220400D00A
--------- beginning of /dev/log/system


--------- beginning of /dev/log/main


** Activity (main) Create, isFirst = true **


Error occurred on line: 79 (main)
java.lang.NullPointerException


at anywheresoftware.b4a.objects.drawable.CanvasWrapper.Initialize(CanvasWrapper.java:76)
at de.amberhome.viewpagerexample.main._activity_create(main.java:346)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:511)
at anywheresoftware.b4a.shell.Shell.runMethod(Shell.java:636)
at anywheresoftware.b4a.shell.Shell.raiseEventImpl(Shell.java:302)
at anywheresoftware.b4a.shell.Shell.raiseEvent(Shell.java:238)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:511)
at anywheresoftware.b4a.ShellBA.raiseEvent2(ShellBA.java:121)
at de.amberhome.viewpagerexample.main.afterFirstLayout(main.java:98)
at de.amberhome.viewpagerexample.main.access$100(main.java:16)
at de.amberhome.viewpagerexample.main$WaitForLayout.run(main.java:76)
at android.os.Handler.handleCallback(Handler.java:615)
at android.os.Handler.dispatchMessage(Handler.java:92)
at android.os.Looper.loop(Looper.java:137)
at android.app.ActivityThread.main(ActivityThread.java:5059)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:511)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:792)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:555)
at dalvik.system.NativeStart.main(Native Method)
** Activity (main) Resume **
 
Last edited:
Upvote 0
Instead of :
Code: Copy
cvsBackground.Initialize(pan)
cvsBackground.DrawLine(10dip, 50dip, 150dip, 100dip, Colors.Black, 5dip)
Use this, you need to adapt the values to your needs :
Code: Copy
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
THANK YOU!

Got it!

Make a panel to look like a line on top of the existing panel.
 
Last edited:
Upvote 0
Back
Top