有谁用API函数StretchBlt()做过图形的缩放?有代码?是否拿来让小弟参考一下?
实在是做不出来了!

解决方案 »

  1.   

    将图片1缩略到图片2,一个小函数。 
    Private Function smallPic()  '将图片缩小至缩略图
    Dim PicErr As Long
    If Picture1.Width <= Picture2.Width And Picture1.Height <= Picture2.Height Then
       '显示原有大小
       PicErr = BitBlt(Picture1.hdc, 0, 0, Picture1.ScaleWidth, Picture1.ScaleHeight, Picture2.hdc, 0, 0, SRCCOPY)
    Else
       '将图片缩小
       Dim C_Width, C_Height As Integer
       If Picture1.Width > Picture1.Height Then   '缩小宽度
          '计算比例
          C_Width = Picture2.ScaleWidth
          C_Height = C_Width * (Picture1.ScaleHeight / Picture1.ScaleWidth)
       Else
          '计算比例
          C_Height = Picture2.ScaleHeight
          C_Width = C_Height * (Picture1.ScaleWidth / Picture1.ScaleHeight)
       End If
       PicErr = StretchBlt(Picture1.hdc, 0, 0, Picture1.ScaleWidth, Picture1.ScaleHeight, Picture2.hdc, 0, 0, C_Width, C_Height, SRCCOPY)
    End If
    End Function
      

  2.   

    Const STRETCH_ANDSCANS = 1
    Const STRETCH_DELETESCANS = 3
    Const STRETCH_HALFTONE = 4
    Const STRETCH_ORSCANS = 2
    Private Const SRCCOPY = &HCC0020Private 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 SetStretchBltMode Lib "gdi32" (ByVal hdc As Long, ByVal nStretchMode As Long) As LongPrivate Sub Command1_Click()
        SetStretchBltMode Picture2.hdc, STRETCH_DELETESCANS
        StretchBlt Picture2.hdc, 0, 0, Picture2.Width, Picture2.Height, Picture1.hdc, 0, 0, Picture1.Width, Picture1.Height, SRCCOPY
    End Sub注意:picture1.autoredraw=true
      

  3.   

    Image1.Stretch = True
    然后调整Image1大小
      

  4.   

    '这有一段视屏放大镜程序,不知对你有没有用.
    '要添加HScroll1,Text1,Timer1三个控件.
    Option Explicit
    Private Type POINTAPI
          X As Long
          Y As Long
    End Type
    Private Declare Function SetWindowPos Lib "user32" (ByVal hwnd As Long, ByVal hWndInsertAfter As Long, ByVal X As Long, ByVal Y As Long, ByVal cx As Long, ByVal cy As Long, ByVal wFlags As Long) As Long
    Private Declare Function GetCursorPos Lib "user32" (lpPoint As POINTAPI) As Long
    Private Declare Function GetDC Lib "user32" (ByVal hwnd As Long) As Long
    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 Const SRCCOPY = &HCC0020
    'Private Const SWP_NOMOVE = &H2
    'Private Const SWP_NOSIZE = &H1
    'Private Const HWND_TOPMOST = -1
    Private Const Flags = &H2 Or &H1
    Dim Pos As POINTAPIPrivate Sub Form_Load()
        Form1.ScaleMode = 3
        SetWindowPos Me.hwnd, -1, 0, 0, 0, 0, Flags
        HScroll1.Max = 59
        HScroll1.Min = 1
        HScroll1.LargeChange = 5
        HScroll1.SmallChange = 1
        
    End Sub
    Private Sub Form_Resize()
        
       Text1.Width = Me.ScaleX(Me.Width, 1, 3) - 9
        Text1.Height = Me.ScaleY(Me.Height, 1, 3) - 50
        HScroll1.Width = Text1.Width
        HScroll1.Top = Text1.Height + 7
    End Sub
    Private Sub HScroll1_Change()
        Form1.Caption = "放大 " & HScroll1.Value & " 倍"
    End SubPrivate Sub AddSee(倍数 As Single, ShowObj As Object)
        Dim Sx As Integer
        Dim Sy As Integer
        Dim ShowW As Long
        Dim ShowH As Long
        Dim PicW As Long
        Dim PicH As Long
        PicW = ShowObj.Width
        PicH = ShowObj.Height
        GetCursorPos Pos
        ShowW = PicW / 倍数
        ShowH = ShowW * (PicH / PicW)
        Sx = IIf(Pos.X < ShowW / 2 Or Pos.X > 640 - ShowW / 2, IIf(Pos.X < ShowW / 2, 0, 640 - ShowW), Pos.X - ShowW / 2)
        Sy = IIf(Pos.Y < ShowH / 2 Or Pos.Y > 480 - ShowH / 2, IIf(Pos.Y < ShowH / 2, 0, 480 - ShowH), Pos.Y - ShowH / 2)
        StretchBlt GetDC(ShowObj.hwnd), 0, 0, PicW, PicH, GetDC(0), Sx, Sy, ShowW, ShowH, SRCCOPY
    End SubPrivate Sub Timer1_Timer()
        AddSee HScroll1.Value, Text1
    End Sub