Fit Image on screen

Merlot2309

Active Member
Licensed User
Longtime User
Hello,

In general I go thru all the posts, just because I learn from the questions and answers.

I would like to advice you to have a look at the Canvas view.

Succes,
Helen.
 
Upvote 0

canalrun

Well-Known Member
Licensed User
Longtime User
How to fit image on screen.pls advise

Hi,
I had the same question a few weeks ago. This is what I came up with and it seems to work very well, and is very convenient during implementation.

Each "page" of my application has a panel. I make my panel color opaque white, but I've seen examples on this forum for bitmaps and gradients.

I add user controls (views) such as buttons, text boxes, image viewers, etc. making sure their parent is set to the panel.

During Activity_Create, I set the dimensions of the panel:

panel1.left = 0
panel1.top= 0
panel1.width= 100%x 'this is 100% of the device screen width
panel1.height= 100%y 'this is 100% of the device screen height

Suppose, using the designer, I had added an ImageView, being sure to make the parent panel1. Call it imgV1. I had added a PNG ti imgV1 in the designer. The PNG size let's suppose is 173 pixels wide and 257 pixels high. I want it to be 90% of the screen width, centered, and with the correct aspect ratio. By default, the ImageView scales the image to fit the size of the view. (this assumes portrait)

imgV1.width = 90%x
imgV1.height= imgV1.width * (257.0/173.0)
imgV1.left=5%x
imgV1.top= (panel1.height - imhV1.height) / 2.0

If I have a second panel, say panel2, I also scale that full-screen and put whatever controls (views) I need on it making sure that the parent is set to panel2. To switch display pages, I:

panel1.enabled = False
panel1.visible= False

panel2.enabled = True
panel2.visible= True
panel2.BringToFront

I hope this addresses your question.
Barry.
 
Last edited:
Upvote 0
Top