VB.Net图像文件缩放变换的代码
乐博网lob.cn提示:此代码运行环境为vb.net2008
Public Class Form1 '浏览图像文件 Private Sub button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles button2.Click Me.openFileDialog1.Filter = "图像文件(JPeg,Gif,Bmp,etc.)|*.jpg;*.jpeg;*.gif; *.bmp; *.tif; *.tiff; *.png| JPeg 文件 (*.jpg;*.jpeg)|*.jpg;*.jpeg |GIF 文件 (*.gif)|*.gif |BMP 文件 (*.bmp)|*.bmp|Tiff 文件 (*.tif;*.tiff)|*.tif;*.tiff|Png 文件 (*.png)| *.png |所有文件(*.*)|*.*" If (Me.openFileDialog1.ShowDialog() = DialogResult.OK) Then Me.textBox1.Text = Me.openFileDialog1.FileName Dim MyImage = Image.FromFile(Me.textBox1.Text) Me.pictureBox1.Image = MyImage End If End Sub
'缩放变换 更多 .net代码 关注lob.cn Private Sub button4_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles button4.Click Dim MyImage = Image.FromFile(Me.textBox1.Text) Dim MyAttributes As New System.Drawing.Imaging.ImageAttributes() Dim MyWidth = MyImage.Width Dim MyHeight = MyImage.Height Dim MyElements As Single()() = {New Single() {0.75F, 0, 0, 0, 0}, New Single() {0, 0.65F, 0, 0, 0}, New Single() {0, 0, 0.5F, 0, 0}, New Single() {0, 0, 0, 1.0F, 0}, New Single() {0, 0, 0, 0, 1.0F}} Dim MyMatrix As New System.Drawing.Imaging.ColorMatrix(MyElements) MyAttributes.SetColorMatrix(MyMatrix, System.Drawing.Imaging.ColorMatrixFlag.Default, System.Drawing.Imaging.ColorAdjustType.Bitmap) Me.pictureBox1.CreateGraphics().DrawImage(MyImage, New Rectangle(0, 0, MyWidth, MyHeight), 0, 0, MyWidth, MyHeight, GraphicsUnit.Pixel, MyAttributes) End Sub End Class
|