2020年6月10日 星期三

vb.net 將PictureBox裡的圖片縮小(非BMP) [Resize PictureBox Image]


 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
    Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        PictureBox1.Image = Image.FromFile("C:\Users\Public\Pictures\Sample Pictures\Chrysanthemum.jpg")
        Dim a As Graphics
        Dim dx = (PictureBox2.Height - (3 / 4 * PictureBox2.Height)) / 2 '計算上下邊界 
        PictureBox2.Image = New Bitmap(100, 100)
        a = Graphics.FromImage(PictureBox2.Image)
        a.DrawImage(PictureBox1.Image, 0, CInt(dx), 100, CInt(PictureBox2.Height - 2 * dx)) '不就是照比例貼過去嘛... 

 'New
        Dim pbxTemp As New PictureBox
        pbxTemp.Image = Image.FromFile("C:\Users\Public\Pictures\Sample Pictures\Chrysanthemum.jpg")
        Dim a As Graphics
        Dim Porcent As Double = pbxTemp.Image.Height / 100
        Dim imgWidth As Integer = pbxTemp.Image.Width / Porcent
        PictureBox1.Image = New Bitmap(imgWidth, 100)
        a = Graphics.FromImage(PictureBox1.Image)
        a.DrawImage(pbxTemp.Image, 0, 0, imgWidth, 100) '不就是照比例貼過去嘛... 
    End Sub

沒有留言:

張貼留言