picturebox放大、缩小、旋转、拖拽

1、加载图像

   Dim temp As Byte()
        Try
            If cxh <> "" Then
                temp = myYw.GetPic(cxh)
                Dim stream As New MemoryStream(temp)
                picfile.Image = Image.FromStream(stream)
                picfile.SizeMode = PictureBoxSizeMode.AutoSize
                txtkuan.Text = picfile.Width
                txtgao.Text = picfile.Height
            End If

        Catch ex As Exception
        End Try

 

   '获取缩略图
        Public Function GetPic(ByVal xh As String) As Byte()
            Dim strSQL As String
            Dim dr As SqlDataReader
            strSQL = "Select * From ec_m Where xh=" & xh
            Try
                dr = SqlHelper.ExecuteReader(o.GetConn, CommandType.Text, strSQL)
                If dr.Read Then
                    Return DirectCast(dr("cd"), Byte())
                End If
                'Return SqlHelper.ExecuteScalar(o.GetConn, CommandType.Text, strSQL)
            Catch ex As Exception
            Finally
                If Not dr Is Nothing Then dr.Close()
            End Try

        End Function

 

 

2、缩小

   picfile.SizeMode = PictureBoxSizeMode.StretchImage
        picfile.Width = CInt(picfile.Width * 0.8)
        picfile.Height = CInt(picfile.Height * 0.8)

3、旋转

      Dim bmp As New Bitmap(picfile.Image)
        picfile.SizeMode = PictureBoxSizeMode.AutoSize
        bmp.RotateFlip(RotateFlipType.Rotate90FlipNone)
        picfile.Image = bmp
        txtgao.Text = picfile.Height
        txtkuan.Text = picfile.Width
4、最适合大小

    Dim tempkuan As Double
        Dim tempgao As Double

        picfile.SizeMode = PictureBoxSizeMode.StretchImage
        If CDbl(txtkuan.Text) > 1000 Then
            If txtgao.Text > 500 Then
                '1300*2300
                tempkuan = (1000 / picfile.Width)
                tempgao = (500 / picfile.Height)
                If tempkuan > tempgao Then
                    picfile.Width = CDbl(tempgao * txtkuan.Text)
                    picfile.Height = CDbl(tempgao * txtgao.Text)
                Else
                    picfile.Width = CDbl(tempkuan * txtkuan.Text)
                    picfile.Height = CDbl(tempkuan * txtgao.Text)
                End If
            Else

                '1200*490
                picfile.Width = (1000 / picfile.Width) * txtkuan.Text
                picfile.Height = (1000 / picfile.Width) * txtgao.Text
            End If
        Else
            If txtgao.Text > 500 Then
                tempgao = (500 / picfile.Height)
                picfile.Width = CDbl(tempgao * txtkuan.Text)
                picfile.Height = CDbl(tempgao * txtgao.Text)
            Else
                picfile.Width = txtkuan.Text
                picfile.Height = txtgao.Text
            End If
        End If

 

5、拖拽

‘先声明

    Dim mousePos0 As Point
    Dim canMove0 As Boolean

’事件处理

  Private Sub picfile_MouseUp(ByVal sender As Object, ByVal e As System.Windows.Forms.MouseEventArgs) Handles picfile.MouseUp
        canMove0 = False
    End Sub

    Private Sub picfile_MouseMove(ByVal sender As Object, ByVal e As System.Windows.Forms.MouseEventArgs) Handles picfile.MouseMove
        If canMove0 Then
            picfile.Location = New Point(picfile.Location.X - mousePos0.X + e.X, picfile.Location.Y - mousePos0.Y + e.Y)
        End If
    End Sub

    Private Sub picfile_MouseDown(ByVal sender As Object, ByVal e As System.Windows.Forms.MouseEventArgs) Handles picfile.MouseDown
        canMove0 = True
        mousePos0 = New Point(e.X, e.Y)
    End Sub

 

 

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值