borderAndreaVB free resources for Visual Basic developersborder

borderAndreaVB Visual Basic and VB.NET source code resources - Copyright © 1999-2007 Andrea Tincaniborder

AndreaVB | Forum | News | Downloads | Register | Help | Member List | Statistics | Search | PM | Profile

Print This Topic
Previous Topic (VB Project Mapper)Next Topic (How to hidden Style and Size from Font Dialog box) New Topic New Poll Post Reply
AndreaVB Forum : VB General : PictureBox Problem!!! Help!
Poster Message
NeedHelpPlz
Level: Guest


icon PictureBox Problem!!! Help!  Archived to Disk

JLRodgers should know this one... hopefully.

In my program I need to load an image into a picturebox and resize it to a specific size. How is this done? I already can load the image into the picturebox... that's easy.

But I need to know once it's there, how to resize it to be 305x210 pixels.

To do this, I use the "Open" dialog box, and then whatever file the user selects is loaded into the picturebox. This works fine.

I need to know how to get to always resize the loaded image to 305x210 pixels.

Help!
Thanks!

04-06-2002 at 09:16 PM
| Quote Reply
JLRodgers
Level: Moderator

Registered: 04-04-2002
Posts: 1616
icon Re: PictureBox Problem!!! Help!  Archived to Disk

If you can use an image control instead, it has a stretch feature...

Otherwise, try the following (of course, picture1 will have to have a picture loaded):

Option Explicit

Private Declare Function StretchBlt Lib "gdi32" (ByVal hdc As Long, ByVal X As Long, ByVal Y As Long, ByVal nWidth As Long, ByVal nHeight As Long, ByVal hSrcDC As Long, ByVal xSrc As Long, ByVal ySrc As Long, ByVal nSrcWidth As Long, ByVal nSrcHeight As Long, ByVal dwRop As Long) As Long

Private Sub Form_Load()
    Me.Visible = True
    DoEvents
' Set the graphic mode to persistent
    Me.AutoRedraw = True
' API uses pixels, set pixels for the form, and boxes
' that way can just set width  & height to desired pixel
    Me.ScaleMode = vbPixels
    Picture1.ScaleMode = vbPixels
    Picture2.ScaleMode = vbPixels
    
' Set the width and height
    Picture2.Width = 210
    Picture2.Height = 305
    DoEvents
' Stretch the picture
    StretchBlt Picture2.hdc, 0, 0, 210, 305, Picture1.hdc, 0&, 0&, Picture1.Width, Picture1.Height, vbSrcCopy
End Sub

05-06-2002 at 12:13 AM
View Profile Send Email to User Show All Posts Visit Homepage | Quote Reply
NeedHelpPlz
Level: Guest

icon Re: PictureBox Problem!!! Help!  Archived to Disk

Thanks JL, works now.

05-06-2002 at 10:39 PM
| Quote Reply
AndreaVB Forum : VB General : PictureBox Problem!!! Help!
Previous Topic (VB Project Mapper)Next Topic (How to hidden Style and Size from Font Dialog box) New Topic New Poll Post Reply
Surf To:


Not Logged In? Username: Password: Lost your password?
Partners: Download Actual Software | Free Software Download
borderAndreaVB free resources for Visual Basic developersborder

borderAndreaVB Visual Basic and VB.NET source code resources - Copyright © 1999-2007 Andrea Tincaniborder