版权声明:本文为博主原创文章,转载请在显著位置标明本文出处以及作者网名,未经作者允许不得用于商业目的。
本节主要从代码介绍Bitmap的几个方法。
设计界面:
为了便于观察,请将PicDest的SizeMode设置为:AutoSize。
cbRotateFlip的Items属性设置为RotateFlipType的成员名称:
主要代码:
'窗体级变量,保存加载的图片
Dim sourceImg As Bitmap
'载入图片
Private Sub btnLoadimg_Click(sender As Object, e As EventArgs) Handles btnLoadimg.Click
sourceImg = New Bitmap("d:\15z.jpg")
'或者:
'sourceImg = Image.FromFile("d:\15z.jpg")
picSource.Image = sourceImg
End Sub
'旋转、翻转
Private Sub cbRotateFlip_SelectedIndexChanged(sender As Object, e As EventArgs) Handles cbRotateFlip.SelectedIndexChanged
Dim destImg As Bitmap
destImg = sourceImg.Clone
Select Case cbRotateFlip.Text
Case "Rotate180FlipX"
destImg.RotateFlip(RotateFlipType.Rotate180FlipX)
Case "Rotate180FlipNone"
destImg.RotateFlip(RotateFlipType.Rotate180FlipNone)
Case "Rotate180FlipXY"
destImg.RotateFlip(RotateFlipType.Rotate180FlipXY)
Case "Rotate180FlipY"
destImg.RotateFlip(RotateFlipType.Rotate180FlipY)
Case "Rotate270FlipNone"
destImg.RotateFlip(RotateFlipType.Rotate270FlipNone)
Case "Rotate270FlipX"
destImg.RotateFlip(RotateFlipType.Rotate270FlipX)
Case "Rotate270FlipXY"
destImg.RotateFlip(RotateFlipType.Rotate270FlipXY)
Case "Rotate90FlipNone"
destImg.RotateFlip(RotateFlipType.Rotate90FlipNone)
Case "Rotate90FlipX"
destImg.RotateFlip(RotateFlipType.Rotate90FlipX)
Case "Rotate90FlipXY"
destImg.RotateFlip(RotateFlipType.Rotate90FlipXY)
Case "Rotate90FlipY"
destImg.RotateFlip(RotateFlipType.Rotate90FlipY)
Case "RotateNoneFlipNone"
destImg.RotateFlip(RotateFlipType.RotateNoneFlipNone)
Case "RotateNoneFlipX"
destImg.RotateFlip(RotateFlipType.RotateNoneFlipX)
Case "RotateNoneFlipXY"
destImg.RotateFlip(RotateFlipType.RotateNoneFlipXY)
Case "RotateNoneFlipY"
destImg.RotateFlip(RotateFlipType.RotateNoneFlipY)
End Select
picDest.Image = destImg
End Sub
'保存图片
Private Sub btnSave_Click(sender As Object, e As EventArgs) Handles btnSave.Click
picDest.Image.Save("d:\1515.jpg", Imaging.ImageFormat.Jpeg)
End Sub
运行效果:
由于.net平台下C#和vb.NET很相似,本文也可以为C#爱好者提供参考。
学习更多vb.net知识,请参看vb.net教程 目录
————————————————
版权声明:本文为CSDN博主「VB.Net」的原创文章,遵循CC 4.0 BY-SA版权协议,转载请附上原文出处链接及本声明。