PHP User Warning: fetch_template() calls should be replaced by the vB_Template class. Template name: bbcode_highlight in ..../includes/functions.php on line 4197
[RESOLVED] picturebox: resize image to fit-VBForums
Results 1 to 10 of 10

Thread: [RESOLVED] picturebox: resize image to fit

  1. #1

    Thread Starter
    Addicted Member
    Join Date
    Jul 2002
    Location
    new zealand (kiwi)!
    Posts
    197

    Resolved [RESOLVED] picturebox: resize image to fit

    how can I make a .GIF file be automatically resized to fit a
    picturebox on loading?
    Code from this site I have tried:
    Dim Pic As Picture
    Picture1.AutoRedraw = True 'Here or in Properties Window
    Set Pic = LoadPicture("C:\MyPic.Jpg")
    Picture1.PaintPicture Pic, 0, 0, Picture1.ScaleWidth, Picture1.ScaleHeight
    Set Picture1.Picture = Picture1.Image

    but VB6 doesn't know 'Picture' in the dim statment..

    I would also like to keep the aspect ratio the same as the file .gif
    I guess this 'best fit' is harder to achieve?

  2. #2
    PowerPoster jcis's Avatar
    Join Date
    Jan 2003
    Location
    Argentina
    Posts
    4,423

    Re: picturebox: resize image to fit

    Quote Originally Posted by donW View Post
    ..but VB6 doesn't know 'Picture' in the dim statment..
    That's strange, It's correct to Dim something As Picture in VB, are you sure the error fires in that line exactly?
    Quote Originally Posted by donW View Post
    I would also like to keep the aspect ratio the same as the file .gif
    I guess this 'best fit' is harder to achieve?
    Not so hard, see this post:
    Resize Picture keeping Ratio

  3. #3

    Thread Starter
    Addicted Member
    Join Date
    Jul 2002
    Location
    new zealand (kiwi)!
    Posts
    197

    Re: picturebox: resize image to fit

    Yes I can only dim as PictureBox not picture
    Do I have to load some component or control to get 'Picture' control?

  4. #4
    PowerPoster jcis's Avatar
    Join Date
    Jan 2003
    Location
    Argentina
    Posts
    4,423

    Re: picturebox: resize image to fit

    Picture is not a control, it's an Object and it's native to VB6 so you don't need any component or reference for using it.

  5. #5
    Super Moderator Siddharth Rout's Avatar
    Join Date
    Feb 2005
    Location
    Mumbai, India
    Posts
    11,998

    Re: picturebox: resize image to fit

    Dim Pic As Picture
    This is incorrect...

    Dim pic As PictureBox
    this is correct.

    I have just modified your code little bit. You don't need to use set pic...

    try this

    vb Code:
    1. Option Explicit
    2. Private Sub Form_Load()
    3.     Picture1.Picture = LoadPicture("C:\test\test.gif")
    4.    
    5.     Picture1.ScaleMode = 3
    6.     Picture1.AutoRedraw = True
    7.     Picture1.PaintPicture Picture1.Picture, _
    8.     0, 0, Picture1.ScaleWidth, Picture1.ScaleHeight, _
    9.     0, 0, Picture1.Picture.Width / 26.46, _
    10.     Picture1.Picture.Height / 26.46
    11.    
    12.     Picture1.Picture = Picture1.Image
    13. End Sub
    A good exercise for the Heart is to bend down and help another up...
    Please Mark your Thread "Resolved", if the query is solved

    Microsoft MVP: 2011 - 2015 IMP Links : Acceptable Use Policy, FAQ
    MyGear:
    OMEN by HP - 15-ce073tx with Win10+Office 2013. || Mac Book Pro (10.6.8) with Office 2011

  6. #6
    PowerPoster jcis's Avatar
    Join Date
    Jan 2003
    Location
    Argentina
    Posts
    4,423

    Re: picturebox: resize image to fit

    Quote Originally Posted by koolsid View Post
    Dim Pic As Picture

    This is incorrect...
    Nope, that's correct. The fact that Picture doesn't appear in the Intellisense list after you write "AS" doesn't mean it's not a valid type.

    If you want to use something that does appear in the list, the following are available and it's practically the same than Picture:
    Code:
        Dim Pic As IPictureDisp
        Dim Pic As StdPicture

  7. #7
    Super Moderator Siddharth Rout's Avatar
    Join Date
    Feb 2005
    Location
    Mumbai, India
    Posts
    11,998

    Re: picturebox: resize image to fit

    Nope, that's correct. The fact that Picture doesn't appear in the Intellisense list after you write "AS" doesn't mean it's not a valid type.
    Oh I didn't know that...

    Forget the above query by OP for a sec... But then how would I use it if I need to use it... not as "IPictureDisp" or "StdPicture" but as "picture"
    A good exercise for the Heart is to bend down and help another up...
    Please Mark your Thread "Resolved", if the query is solved

    Microsoft MVP: 2011 - 2015 IMP Links : Acceptable Use Policy, FAQ
    MyGear:
    OMEN by HP - 15-ce073tx with Win10+Office 2013. || Mac Book Pro (10.6.8) with Office 2011

  8. #8

    Thread Starter
    Addicted Member
    Join Date
    Jul 2002
    Location
    new zealand (kiwi)!
    Posts
    197

    Re: picturebox: resize image to fit

    Hi Coolsid:
    your code runs, but does not resize my (larger than picturebox size) .gifs
    if I alter the 26.46 constants, the size changes.

  9. #9

    Thread Starter
    Addicted Member
    Join Date
    Jul 2002
    Location
    new zealand (kiwi)!
    Posts
    197

    Re: picturebox: resize image to fit

    Resolved my problem with resizing to fit picturebox!
    the picturebox must be set to
    Autosize = false

    thanks all...

  10. #10
    PowerPoster jcis's Avatar
    Join Date
    Jan 2003
    Location
    Argentina
    Posts
    4,423

    Re: picturebox: resize image to fit

    Quote Originally Posted by donW View Post
    Resolved my problem with resizing to fit picturebox!
    the picturebox must be set to
    Autosize = false

    thanks all...
    If you force the image to be the size of the PicBox the size could be distorted, that's solved in the code in the link i added in post #2

Posting Permissions

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



Featured


Click Here to Expand Forum to Full Width