可以做到吗???

解决方案 »

  1.   

    用image控件,如果必须用picturebox,则可以用picturebox自身的PaintPicture方法或者API函数
    StretchBlt。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
      

  2.   

    设置
    Image1.Stretch = True
      

  3.   

    http://community.csdn.net/Expert/topic/3275/3275104.xml?temp=.8720972
      

  4.   

    Image1.Stretch = True.
      

  5.   

    '***************************************************
    '   将图片在PictureBox控件中按比例缩放后,居中显示
    '***************************************************
    Public Sub PictureToCenter(tPic As Picture, PicBox As PictureBox)
        Dim PicH As Long, PicW As Long
        Dim PicBoxW As Long, PicBoxH As Long
        Dim PicRate As Single, PicBoxRate As Single
        Dim NewH As Long, NewW As Long
        
        PicBoxH = PicBox.ScaleHeight
        PicBoxW = PicBox.ScaleWidth
        PicBoxRate = PicBoxW / PicBoxH
        
        PicW = ScaleX(tPic.Width, vbHimetric, PicBox.ScaleMode)
        PicH = ScaleY(tPic.Height, vbHimetric, PicBox.ScaleMode)
        PicRate = PicW / PicH
        
        PicBox.Cls
        If PicH <= PicBoxH And PicW <= PicBoxW Then
            PicBox.PaintPicture tPic, (PicBoxW - PicW) / 2, (PicBoxH - PicH) / 2
            Exit Sub
        End If
        If PicBoxRate < PicRate Then
            NewH = PicBoxW / PicRate
            PicBox.PaintPicture tPic, 0, (PicBoxH - NewH) / 2, PicBoxW, NewH
        Else
            NewW = PicBoxH * PicRate
            PicBox.PaintPicture tPic, (PicBoxW - NewW) / 2, 0, NewW, PicBoxH
        End If
    End Sub'这个过程是我在工程中使用的,可以适应任何比例的图片。
    Private Sub Picture1_Click()
        Dim p As StdPicture
        
        Set p = LoadPicture("H:\My Documents\Img15644950.jpg")
        PictureToCenter p, Picture1
    End Sub
      

  6.   

    干嘛这么麻繁
    用painpicture函数不就行了
      

  7.   

    使用Image控件显示照片,并将它按比例缩放到一个尺寸内。
    Sub ShowPicture(PcitureName As String)
    Dim ZX As Single
    Dim ZY As Single
    With Image1
       .Stretch = False
       .Visible = False
       .Picture = LoadPicture(PictureName)
       ZX = .Width / 155     '假设目标宽度为155像素
       ZY = .Height / 165    '假设目标高度为165像素      
       If ZX > ZY Then
          ZY = ZX
       Else
          ZX = ZY
       End If
       .Stretch = True
       .Width = Int(.Width / ZX)
       .Height = Int(.Height / ZY)
       .Visible = Ture
    End With
    End Sub