将图片生成高清缩略图

  '手动将image画到bitmap中
    Private Sub DrawThumbTest() 
Dim str As String = "C:\Users\hd.song\Desktop\123.jpg"
        Dim array As ArrayList = New ArrayList()
        array.Add(PictureBox1)
        array.Add(PictureBox2)
        array.Add(PictureBox3)
        array.Add(PictureBox4)
        array.Add(PictureBox5)
        array.Add(PictureBox6)
        array.Add(PictureBox7)
        array.Add(PictureBox8)
        array.Add(PictureBox9)
        array.Add(PictureBox10)
        array.Add(PictureBox11)
        array.Add(PictureBox12)
        Dim img As Image = Image.FromFile("C:\Users\hd.song\Desktop\img0.jpg")
        Dim thumbwidth As Integer = 132
        Dim srcWidth As Integer = img.Width
        Dim srcHeight As Integer = img.Height
        Dim thumbHeight As Integer = (srcHeight / srcWidth) * thumbwidth
        Dim bmp As Bitmap = New Bitmap(thumbwidth, thumbHeight)
        Dim g As Graphics = Graphics.FromImage(bmp)
        g.SmoothingMode = Drawing2D.SmoothingMode.HighQuality
        g.CompositingQuality = Drawing2D.CompositingQuality.HighQuality
        g.InterpolationMode = Drawing2D.InterpolationMode.High
        Dim rec As Rectangle = New Rectangle(0, 0, thumbwidth, thumbHeight)
        g.DrawImage(img, rec, 0, 0, srcWidth, srcHeight, GraphicsUnit.Pixel)
        For Each a As Object In array
            a.Image = bmp
        Next
        bmp.Save(str)
End Sub

图片所示使用系统的桌面生成缩略图

'使用image的GetThumbnailImage自动获取缩略图
    Private Sub ThumbTest()
        Dim img As Image = Image.FromFile("C:\Users\hd.song\Desktop\img0.jpg")
        Dim thumbwidth As Integer = 132
        Dim srcWidth As Integer = img.Width
        Dim srcHeight As Integer = img.Height
        Dim thumbHeight As Integer = (srcHeight / srcWidth) * thumbwidth
        Dim thumbnailimage As Image = img.GetThumbnailImage(thumbwidth, thumbHeight, Nothing, Nothing)
        Dim bitmap As Bitmap = New Bitmap(thumbnailimage)
        Dim g As Graphics = Graphics.FromImage(bitmap)
        g.SmoothingMode = Drawing2D.SmoothingMode.HighQuality
        g.CompositingQuality = Drawing2D.CompositingQuality.HighQuality
        g.InterpolationMode = Drawing2D.InterpolationMode.High
        g.DrawImage(thumbnailimage, 0, 0, thumbnailimage.Width, thumbnailimage.Height)
        PictureBox13.Image = bitmap
        PictureBox13.Refresh()
    End Sub

posted @ 2013-07-04 15:43  幽弥狂233  阅读(797)  评论(0编辑  收藏  举报