使用picturebox显示图片,但是由于图片过大,如果autosize 设置成TRUE的话,会超出屏幕显示范围
有没有什么办法能让图片缩小为合适的大小,能在屏幕范围内完全显示。
如果不能用picturebox实现,可有什么其他的控件可以做到图片的缩放吗?谢谢指教!

解决方案 »

  1.   

    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 Declare Function BitBlt Lib "gdi32" (ByVal hDestDC 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 dwRop As Long) As Long'在Form上放一个picture box,并事先定义好一个图片,增加一个按钮
    '例2: 放大或缩小图片
    '放大:
    Private Sub Command1_Click()
        Dim w As Integer, h As Integer
        
        Me.ScaleMode = vbPixels
        w = Picture1.Width
        h = Picture1.Height
        
        StretchBlt Picture1.hdc, 0, 0, w * 2, h * 2, Picture1.hdc, 0, 0, w, h, vbSrcCopy
    End Sub
    '缩小:
    Private Sub Command2_Click()
        Dim w As Integer, h As Integer
        
        Me.ScaleMode = vbPixels
        w = Picture1.Width
        h = Picture1.Height
        
        StretchBlt Me.hdc, 0, 0, w / 2, h / 2, Picture1.hdc, 0, 0, w, h, vbSrcCopy
    End Sub
    '例3: 翻转图片
    '左右翻转
    Private Sub Command3_Click()
        Dim w As Integer, h As Integer
        
        Me.ScaleMode = vbPixels
        w = Picture1.Width
        h = Picture1.Height
        
        StretchBlt Me.hdc, w, 0, -w, h, Picture1.hdc, 0, 0, w, h, vbSrcCopy
    End Sub
    '上下翻转
    Private Sub Command4_Click()
        Dim w As Integer, h As Integer
        
        Me.ScaleMode = vbPixels
        w = Picture1.Width
        h = Picture1.Height
        
        StretchBlt Me.hdc, 0, 0, w / 2, h / 2, Picture1.hdc, 0, 0, w, h, vbSrcCopy
    End Sub
    '左右并且上下翻转
    Private Sub Command5_Click()
        Dim w As Integer, h As Integer
        
        Me.ScaleMode = vbPixels
        w = Picture1.Width
        h = Picture1.Height
        
        StretchBlt Me.hdc, w, h, -w, -h, Picture1.hdc, 0, 0, w, h, vbSrcCopy
    End Sub
      

  2.   

    dim picP as stdpicture
    set picP = loadpicture(....)picture1.paintpicture picp,0,0,picture1.width,picture1.height
      

  3.   

    我建议楼主看看zyl910写的平滑缩放的代码
      

  4.   

    paintpicture最简单,StretchBlt要快一点,不过对于常见的图片,
    需先加上一句:SetStretchBltMode hdc, 4
    不然图片效果会惨不忍睹的!