Get position of image after stretching it 
Author Message
 Get position of image after stretching it
Im loading a picture and setting it as a stdPicture Object and displaying it
as a background picture on the Form. This picture is then stretched using
Paintpicture when the Form is resized (Im trying to make this app adaptable
for most screen resolutions). Several controls are placed on this Form and
they are placed in particular positions that fit with the background
picture. For example, think of a coloured rectangle in this background
picture. A picture control exactly the same size as this rectangle is then
positioned and placed on top of that rectangle. The question: How can I
determine the exact size and position of that rectangle when the Form has
been resized/stretched since its position and size will change when the Form
is resized. I cant use getpixel because there are other coloured rectangles
on the Form. Ive tried holding the oldsize and oldXYpositions of the
rectangle and simply adding or subtracrting the amount of Form resize but it
doesnt seem to work out that way. Any pointers on how to approach this.

Regards

FM



Sun, 13 May 2012 05:17:32 GMT  
 Get position of image after stretching it


Quote:
> Im loading a picture and setting it as a stdPicture Object and displaying it
> as a background picture on the Form. This picture is then stretched using
> Paintpicture when the Form is resized (Im trying to make this app adaptable
> for most screen resolutions). Several controls are placed on this Form and
> they are placed in particular positions that fit with the background
> picture. For example, think of a coloured rectangle in this background
> picture. A picture control exactly the same size as this rectangle is then
> positioned and placed on top of that rectangle. The question: How can I
> determine the exact size and position of that rectangle when the Form has
> been resized/stretched since its position and size will change when the Form
> is resized. I cant use getpixel because there are other coloured rectangles
> on the Form. Ive tried holding the oldsize and oldXYpositions of the
> rectangle and simply adding or subtracrting the amount of Form resize but it
> doesnt seem to work out that way. Any pointers on how to approach this.

One simple way of doing that is to adjust the scale of the form so that it
it always matches the original image size.  Then you can place your controls
where they belong with respect to the image, and because the scale changes
during resize, re-setting those controls to their original position puts them in
the correct place on the form.

A bit harder to explain, perhaps an example will help....

Add a picturebox and a command button to a new form and paste in
the code below.  Note that as you resize the form, the command button
remains inside the drawn box.  Just as the drawn image is stretched and
shrunk as you change the form size, the command button follows suit
because the form's scale has been changed.  Note however that the
command button is set to the exact same size as it was in Form_Load.
Its the changing scale that makes up the difference....

HTH
LFS

Option Explicit
Private IMG As StdPicture
Private IMGX As Long, IMGY As Long

Private Sub Form_Load()
  ' Original image size
  IMGX = Screen.Width / 10
  IMGY = Screen.Height / 10
  ' Init Picturebox
  Picture1.Move 0, 0, IMGX, IMGY
  Picture1.BorderStyle = vbBSNone
  Picture1.BackColor = vbButtonFace
  Picture1.AutoRedraw = True
  Picture1.Visible = False
  ' Draw image
  Picture1.Line (300, 300)-Step(300, 150), vbBlack, B
  ' Save to StdPicture
  Set IMG = Picture1.Image
  ' Set control(s)
  Command1.Move 330, 330, 260, 110
End Sub

Private Sub Form_Paint()
  PaintPicture IMG, 0, 0, ScaleWidth, ScaleHeight
End Sub

Private Sub Form_Resize()
   ' Change scale / stretch image
   Scale (0, 0)-(IMGX, IMGY)
   PaintPicture IMG, 0, 0, ScaleWidth, ScaleHeight
   ' Re-set control(s)
   Command1.Move 330, 330, 260, 110
End Sub



Sun, 13 May 2012 06:07:10 GMT  
 Get position of image after stretching it

Quote:
> Im loading a picture and setting it as a stdPicture Object and displaying it
> as a background picture on the Form. This picture is then stretched using
> Paintpicture when the Form is resized (Im trying to make this app adaptable
> for most screen resolutions). Several controls are placed on this Form and
> they are placed in particular positions that fit with the background
> picture. For example, think of a coloured rectangle in this background
> picture. A picture control exactly the same size as this rectangle is then
> positioned and placed on top of that rectangle. The question: How can I
> determine the exact size and position of that rectangle when the Form has
> been resized/stretched since its position and size will change when the Form
> is resized. I cant use getpixel because there are other coloured rectangles
> on the Form. Ive tried holding the oldsize and oldXYpositions of the
> rectangle and simply adding or subtracrting the amount of Form resize but it
> doesnt seem to work out that way. Any pointers on how to approach this.

Larry's reply is good, but an alternative is a very simple bit of maths.

Say the box is at pixels 10 to 15 of a 20 wide image.

Dim WidthFactor as Single
WidthFactor = Me.ScaleWidth / 20
Command1.Left = WidthFactor * 10
Command1.Width = WidthFactor * 5 '15 - 10

--

i-Catcher Development Team

iCode Systems



Sun, 13 May 2012 19:02:43 GMT  
 Get position of image after stretching it
Much appreciation yet again guys. Ive never had need to use the scale method
as such before now so it wouldnt have occurred to me to change the scale on
resize. Very useful tool. It took a while to understand whats going on there
and to apply it to my app but all seems to be working perfect here now :)
Lots still to do but thats a lot of help.

Regards

FM



Mon, 14 May 2012 06:55:30 GMT  
 
 [ 4 post ] 

 Relevant Pages 

1. Position/Stretch An AVI Image - How ?

2. Position/Stretch an AVI Image ?

3. Apply a stretched image as a listview background

4. Saving image stretch results?

5. auto stretch a image in picturebox to a correct ratio

6. Stretched Image on PictureBox?

7. How to stretch image?

8. Strange Distortion of Image with Stretch = True

9. image/picture control - stretch info

10. stretching Images in VB5

11. what algorithm is behind Image Stretch?

12. Image stretching

 

 
Powered by phpBB® Forum Software