Android Tutorial Drawing lines problem

Attached you find a small test program that shows a known problem in Android when drawing lines with a small slope and with a StrokeWidth of 1.

In some cases the entire line or parts of it are not drawn at all.
When you run the program the default StrokeWidth value equals 1.
In this case the second almost horizontal line is not visible just a few points. Setting the StrokeWidth to 0.99 draws it better.
A StrokeWidth of 0.75 draws even better than a StrokeWidth of 1 but with a darker color.

In the test program you can play with different StrokeWidths to see the differences.
A StrokeWidth of '0' draws lines with a width of 1 pixel (hairline mode).
The problem seems related to the AntiAliasing function for drawing in Android.

The problem also happens when drawing circles.

Erel, is the ANTI_ALIAS_FLAG set by default ?

Best regards.

EDIT: 2012.02.02
Added a Togglebutton to set the antialisaing filter to ON or OFF.
 

Attachments

  • DrawLines.zip
    7 KB · Views: 1,151
  • DrawLines1.jpg
    DrawLines1.jpg
    45.2 KB · Views: 1,597
  • DrawLines2.jpg
    DrawLines2.jpg
    41.3 KB · Views: 1,340
Last edited:

fisray

Member
Licensed User
Longtime User
Hello,
I am learning this very interresting development tool and tried to compile this application.
I get an error message:

Error description: Unknown type: reflector
Are you missing a library reference?
Occurred on line: 88
Dim r As Reflector

I have the same problem with another app: SQLDbUtils

Can you tell me what I am missing?

Many thanks in advance,
Raymond
 

HGGER

Member
Licensed User
Longtime User
Hi Klaus!

I downloaded the drawlines examples and did a few tests with them.
It worked very well. The questions I have on that topic are as follow:

1) In your example you do the draw line process always in a canvas.
I wonder if that could be done straight in the Activity?

2) The canvas is not available in the designer. I wonder how to access the canvas before the program is loaded? In order to have the controls nicely oriented in the vertical center I use a method which dose that for me,
see the example below:

lblheadline1.Left = pnlStart.Width / 2 - lblheadline1.Width / 2

This will center the label regardless how the device is rotated. I would like to do something similar with the canvas.

3) I want to draw a rectangle which surrounds a few label and text boxes to group these controls. If there is a better way of doing it please let me know.
Dim recthg As Rect
Dim hx1, hx2, hy1, hy2 As Float
hx1 = 20%x
hx2 = 80%x
hy1 = 20%y
hy2 = 80%Y
recthg.Initialize(hx1,hy1,hx2,hy2)
cvsTest.DrawRect(recthg, Colors.Red,False,5dip)

Best Regards

Heinz
 

klaus

Expert
Licensed User
Longtime User
1) In your example you do the draw line process always in a canvas.
To draw something you need a Canvas.
The Canvas is nothing else than a drawing tool.
The Canvas draws onto a bitmap, which can be a mutable bitmap or the background bitmap of a View.
The most common views to draw on are:
- Activity
- ImageView
- Panel
When you initialize the Canvas you set the destination bitmap.
In the example program the Canvas points onto the activity:
B4X:
cvsTest.Initialize(Activity)
To group different Views you can also put those on Panels with different background colors.
The advantage is when you move the panel all child views of this panal move also and if you want to hide the group of views you just hide the panel.

Best regards.
 
Top