设计界面:
为了便于观察,请将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 教程 目录