PictureBox在运行时是否可以改变大小?能否做到像Photoshop中的图片自由变换效果。谁能提供个示例。

解决方案 »

  1.   

    大小缩放可以用Image控件,但要实现梯形缩放等要用api了
      

  2.   

    同楼上,但如果不用API,就用PictrueBox控件的PaintPicture方法吧。
    参考:http://www.china-askpro.com/msg1/qa97.shtml
      

  3.   

    PaintPicture适合做图片的缩放和翻转,但要做到photoshop中自由变换的效果,那非得用api了。
      

  4.   

    自由变换用API也是实现不了的,要自己做算法。
      

  5.   

    图像切换效果,其实网上有很多例子。如:百叶窗、透明效果、淡入淡出、水平拉幕、垂直拉幕等,都得用API。我曾经做了一个影集软件,做了256个图像切换特技,其中很多是自己创造的。
      

  6.   

    '添加 Image1  Label1(0) '注意Label1是数组 Index要设为0
    'Image图片在处理拖动或拉大拉小都会闪,只能用API再处理,但代码长在这里不方便贴,给我邮箱吧
    '使用Image原因就是它可以拉伸(Stretch属性)PictureBox没有,否则Picture就好处理了.Dim i&, oldX!, oldY!, bShow As Boolean, bMove As Boolean
    Private Sub Form_Load()
       Label1(0).Width = 75: Label1(0).Height = 75: Label1(0).BackColor = QBColor(1): Label1(0).Caption = "": Label1(0).Visible = False
       If Label1.Count = 1 Then
          For i = 1 To 7
             Load Label1(i)
          Next
       End If
       Image1.Stretch = True
       bShow = False
       Me.Width = 8000: Me.Height = 6000: Me.Caption = "CBM666的运行时期改变图象尺寸"
       Me.Move (Screen.Width - Me.Width) \ 2, (Screen.Height - Me.Height) \ 2
    End SubPrivate Sub Form_Click()
       If bShow Then bShow = False: HideLabel1s
    End SubPrivate Sub Form_DragDrop(Source As Control, X As Single, Y As Single)
       SetLabel1s Image1
    End SubPrivate Sub Form_DragOver(Source As Control, X As Single, Y As Single, State As Integer)
       SizeObject Source.Index, X, Y
    End SubPrivate Sub Form_MouseMove(Button As Integer, Shift As Integer, X As Single, Y As Single)
       Me.MousePointer = vbDefault
    End SubPrivate Sub Image1_MouseUp(Button As Integer, Shift As Integer, X As Single, Y As Single)
        bMove = False
        For i = 0 To 7
           Label1(i).Visible = True
        Next
    End SubPrivate Sub Label1_MouseDown(Index As Integer, Button As Integer, Shift As Integer, X As Single, Y As Single)
       HideLabel1s
       Label1(Index).Drag
    End SubPrivate Sub Image1_DragDrop(Source As Control, X As Single, Y As Single)
       SetLabel1s Image1
    End SubPrivate Sub Image1_DragOver(Source As Control, X As Single, Y As Single, State As Integer)
       With Image1
          Select Case Source.Index
             Case 0
                .Top = .Top + Y
                .Left = .Left + X
                .Width = .Width - X
                .Height = .Height - Y
             Case 1
                .Left = .Left + X
                .Width = .Width - X
             Case 2
                .Width = .Width - X
                .Height = Y
                .Left = .Left + X
             Case 3
                .Height = .Height - Y
                .Top = .Top + Y
             Case 4
                .Height = Y
             Case 5
                .Width = X
                .Height = .Height - Y
                .Top = .Top + Y
             Case 6
                .Width = X
             Case 7
                .Width = X
                .Height = Y
          End Select
       End With
    End SubPrivate Sub Label1_MouseMove(Index As Integer, Button As Integer, Shift As Integer, X As Single, Y As Single)
       Select Case Index
          Case 0, 7
             Label1(Index).MousePointer = 8
          Case 1, 6
             Label1(Index).MousePointer = 9
          Case 2, 5
             Label1(Index).MousePointer = 6
          Case 3, 4
             Label1(Index).MousePointer = 7
       End Select
    End SubPrivate Sub SetLabel1s(SelectedControl As Control)
       With SelectedControl
          For i = 0 To 7
             Select Case i
                Case 0
                   Label1(i).Left = .Left - Label1(i).Width
                   Label1(i).Top = .Top - Label1(i).Height
                Case 1
                   Label1(i).Left = .Left - Label1(i).Width
                   Label1(i).Top = .Top + ((.Height - Label1(i).Height) / 2)
                Case 2
                   Label1(i).Left = .Left - Label1(i).Width
                   Label1(i).Top = .Top + .Height
                Case 3
                   Label1(i).Left = .Left + ((.Width + Label1(i).Width) / 2)
                   Label1(i).Top = .Top - Label1(i).Height
                Case 4
                   Label1(i).Left = .Left + ((.Width + Label1(i).Width) / 2)
                   Label1(i).Top = .Top + .Height
                Case 5
                   Label1(i).Left = .Left + .Width
                   Label1(i).Top = .Top - Label1(i).Height
                Case 6
                   Label1(i).Left = .Left + .Width
                   Label1(i).Top = .Top + ((.Height - Label1(i).Height) / 2)
                Case 7
                   Label1(i).Left = .Left + .Width
                   Label1(i).Top = .Top + .Height
             End Select
             Label1(i).Visible = True
          Next
       End With
    End SubPrivate Sub SizeObject(Label1Index As Integer, X As Single, Y As Single)
       On Error Resume Next
       With Image1
          Select Case Label1Index
             Case 0
                .Width = .Width + (.Left - X)
                .Height = .Height + (.Top - Y)
                .Left = X
                .Top = Y
             Case 1
                .Width = .Width + (.Left - X)
                .Left = X
             Case 2
                .Width = (.Left - X) + .Width
                .Height = Y - .Top
                .Left = X
             Case 3
                .Height = .Height + .Top - Y
                .Top = Y
             Case 4
                .Height = Y - .Top
             Case 5
                .Width = X - .Left
                .Height = .Height + .Top - Y
                .Top = Y
             Case 6
                .Width = X - .Left
             Case 7
                .Width = X - .Left
                .Height = Y - .Top
          End Select
       End With
       KeyEdit = "Move"
    End SubPrivate Sub HideLabel1s()
       For i = 0 To 7
          Label1(i).Visible = False
       Next
    End SubPrivate Sub Image1_MouseDown(Button As Integer, Shift As Integer, X As Single, Y As Single)
       bMove = True
       oldX = X: oldY = Y
    End SubPrivate Sub Image1_MouseMove(Button As Integer, Shift As Integer, X As Single, Y As Single)
       If bMove Then
          Image1.Left = X - oldX + Image1.Left
          Image1.Top = Y - oldY + Image1.Top
          For i = 0 To 7
             Label1(i).Visible = False
          Next
       End If
    End SubPrivate Sub Image1_Click()
       If Label1.Count = 1 Then
          For i = 1 To 7
             Load Label1(i)
          Next
       End If
       bShow = True
       SetLabel1s Image1
    End Sub
    效果图:
    http://p.blog.csdn.net/images/p_blog_csdn_net/cbm666/366646/o_Resize.jpg