Results 1 to 6 of 6

Thread: Resizing Graphics at runtime

  1. #1

    Thread Starter
    New Member
    Join Date
    Jan 1999
    Location
    Germantown,Maryland; USA
    Posts
    6

    Question

    I've only worked with VB for a relatively small amount of time, but I have a project that require me to display a graphic. The graphics vary in size, but I am displaying them in a 320 X 240 window. This size is required because of all other other data that needs to be on the window.

    How do I resize the graphic, at runtime, to match the size of my display windows and maintain the original graphics porportions?

    I hope someone can help me, thanks in advance.
    Sean

  2. #2
    New Member
    Join Date
    May 2000
    Posts
    5
    This how I do it. It could probably be done simpler, but I'm
    a complex person. Anyway you get the general idea.
    Stick this where you load your image. I use this with an
    image. Dunno if it does the same with a picture box or not.
    ----------------------------------------------------------
    Dim ww As Integer
    Dim hh As Integer
    Dim yy As Double
    Dim cc As Integer
    Dim boxwidth as Integer
    Dim boxheight as Integer

    'Set stretch to false if you want small images to stay small.
    Imagename.Visible = False 'So they don't see it resize.
    Imagename.Picture = LoadPicture( whatever picture )
    ww = Imagename.Width
    hh = Imagename.Height
    boxwidth = <desired width of of your Image box>
    boxheight = <desired height of of your Image box>

    'If the Image is bigger than the box, proportionately resize the Image.
    If ww > boxwidth Or hh > boxheight Then
    'Set stretch to true if default is False.
    If ww > hh Then
    yy = boxwidth / ww
    Imagename.Width = boxwidth
    cc = CInt(hh * yy)
    Imagename.Height = cc
    ElseIf hh > ww Then
    yy = boxheight / hh
    Imagename.Height = boxheight
    cc = CInt(ww * yy)
    Imagename.Width = cc
    Else 'The height and width of the loaded image are the same.
    Me.Image1.Height = boxheight
    Me.Image1.Width = boxwidth
    End If
    End If

    Imagename.Visible = True



    [Edited by wchilde on 06-06-2000 at 11:56 AM]

  3. #3
    Guest
    Or you can use the PaintPicture method and set the Width and Height to whatever you want.

    Code:
    Picture2.PaintPicture Picture1.Picture, 0, 0, 320, 240

  4. #4

    Thread Starter
    New Member
    Join Date
    Jan 1999
    Location
    Germantown,Maryland; USA
    Posts
    6

    Talking

    Thank you wchilde. After looking at the code, I should have know that. I guess I was making it harder than it really was.

    I thank you, my employer thanks you.

    Sean

  5. #5

    Thread Starter
    New Member
    Join Date
    Jan 1999
    Location
    Germantown,Maryland; USA
    Posts
    6
    I also want to thank you Megatron. I'm going to try both methods and see the effects.

    Now if only I could eliminate all the other bugs scathered throughout this program.

    Sean

  6. #6
    Guest
    Other bugs? I could try helping you out with some of them.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width