Drawing on a panel

NetStorm

Member
Licensed User
Longtime User
Hey,

I have loaded a file of coordinates in to my app and drawn it on to a panel. It has drawn it to the top left corner and is rather small in conjunnction with the coordinates.

Is there a way I can zoom to fit the drawing on the panel, so that the drawing is larger than the coordinates make it, basically a zoom to fit?

Thanks for any help. Much appreciated.

Regards,

Dan.
 

klaus

Expert
Licensed User
Longtime User
You must be more precise.
The panel coordinates are pixels, the upper left corner's coordinates are 0, 0.
What kind of coordinates are you speeking of ?
What are the min, max values of the coordinates ?
What is the size of the panel ?

Best regards.
 
Upvote 0

NetStorm

Member
Licensed User
Longtime User
The min max values vary depending on the file but are readable. The coordiantes are from a DXF autocad file.
 
Upvote 0

kickaha

Well-Known Member
Licensed User
Longtime User
Simplistically to fill the panel:

Get your maximum x coord value - call this MaxX
Get your maximum y coord value - call this MaxY

Get the panel Width (its x value) - call this DisplayX
Get the panel height (its y value) - call this DisplayY

ScaleX = DisplayX / MaxX
ScaleY = DisplayY / MaxY

then scale each coordinate pair with x*ScaleX, y*ScaleY

To maintain aspect ratio you can use

B4X:
If ScaleX > ScaleY Then

ScaleX = ScaleY

Else

ScaleY = ScaleX 

End If
 
Upvote 0

klaus

Expert
Licensed User
Longtime User
Attached you find a small test program that shows you how to do it.

Best regards.
 

Attachments

  • Graphics.zip
    6.6 KB · Views: 431
  • Graphics.jpg
    Graphics.jpg
    17.9 KB · Views: 431
Upvote 0

NetStorm

Member
Licensed User
Longtime User
Thanks alot! Still doesn't seem to fill he panel but is bigger than it was. I'll keep working at it, see if I can make it work.
 
Upvote 0
Top