1、创建项目,见图:
2、添加界面控件,按照自己的喜好排列,需要添加的控件如下:“OpenFileDialog”“picturebox”四个“button”。
3、接下来是代码添加,首先添加"using System.IO;"引用,因为我们需要操作文件,只要是需要操作文件,基本都要用引用这个。
4、添加三个变量 private int ImageCount; private List<string> 朐袁噙岿ImagePaths = new List<string>(); private int nowCount = 0;这几个变量是为下一张图片这个功能调用的。
5、在第一个打开图片“button”中添加如下代码:if (DialogResult.蚪嬷吃败OK == openFileDialog1.ShowDialog()) { pictureBox1.Image = Image.FromFile(openFileDialog1.FileName); foreach (string Path in Directory.GetFiles(System.IO.Path.GetDirectoryName(openFileDialog1.FileName))) { ImagePaths.Add(Path); } if (ImagePaths.Count != 0) { ImageCount = ImagePaths.Count; } }这段代码的大概意思为:调用openFileDialog打开文件,并且将文件路径提交给pictureBox显示,还有就是给下一张图片调用的部分代码。
6、在下一张的“button”中添加如下代码:if (nowCount < ImageCount) { this.pictureBox1.Image = Bitmap.FromFile(ImagePaths[nowCount]); nowCount++; }这段代码的一位为,获取下一张显示图片,并且在“pictureBox”控件中显示出来。
7、在旋转90的“button”中添加代码:this.pictureBox1.Image.RotateFlip(RotateFlipType.Rotate90FlipNone); this.pictureBox1.Refresh();代码意思为,将当前图片旋转90度,在刷新显示。
8、在旋转180的“button”中添加代码:this.pictureBox1.Image.RotateFlip(RotateFlipType.Rotate180FlipNone); this.pictureBox1.Refresh();代码意思为,将当前图片旋转180度,在刷新显示。
9、在这一步,基本完成了我们对图片查看的基本需求,见效果图。