using System;using System.Collections.Generic;using System.ComponentModel;using System.Data;using System.Drawing;using System.Linq;using System.Text;using System.Threading.Tasks;using System.Windows.Forms;using System.IO ;namespace 圖片瀏覽器{? ? public partial class Form1 : Form? ? {? ? ? ? //不知道變量類(lèi)型也沒(méi)有錯(cuò)? ? ? ? String str;//當(dāng)前打開(kāi)的圖片的絕對(duì)路徑存放地址? ? ? ? int k;//打開(kāi)文件夾下已經(jīng)排好序的第k張照片? ? ? ? int size;//文件夾下的圖片文件個(gè)數(shù)? ? ? ? string[] strfiles;//文件夾下的所有圖片地址? ? ? ? public Form1()? ? ? ? {? ? ? ? ? ? InitializeComponent();? ? ? ? }? ? ? ? private void OpenToolStripMenuItem1_Click(object sender, EventArgs e)//打開(kāi)單張照片? ? ? ? {? ? ? ? ? ? OpenFileDialog OpenFileDialog = new OpenFileDialog();? ? ? ? ? ? OpenFileDialog.Filter = "jpg文件(*.jpg)|*.ipg|bmp文件(*.bmp)|*.bmp|png文件(*.png)|*.png";? ? ? ? ? ? if (OpenFileDialog.ShowDialog() == DialogResult.OK)? ? ? ? ? ? {? ? ? ? ? ? ? ? this.pictureBox1.Image = System.Drawing.Image.FromFile(OpenFileDialog.FileName);? ? ? ? ? ? ? ? str = OpenFileDialog.FileName;? ? ? ? ? ? ? ? this.SaveToolStripMenuItem.Visible = true;? ? ? ? ? ? ? ? this.FormatChangeToolStripMenuItem.Visible = true;? ? ? ? ? ? ? ? this.EditToolStripMenuItem.Visible = true;? ? ? ? ? ? }? ? ? ? }? ? ? ? private void OpenFolderToolStripMenuItem_Click(object sender, EventArgs e)//打開(kāi)一個(gè)目錄下的圖片文件? ? ? ? {? ? ? ? ? ? int i = 0;? ? ? ? ? ? for (int j = 0; j < 100; j++)? ? ? ? ? ? {? ? ? ? ? ? ? ? strfiles[j] = "";? ? ? ? ? ? }? ? ? ? ? ? FolderBrowserDialog n = new FolderBrowserDialog();? ? ? ? ? ? if (n.ShowDialog() == DialogResult.OK)? ? ? ? ? ? {? ? ? ? ? ? ? ? try? ? ? ? ? ? ? ? {? ? ? ? ? ? ? ? ? ? DirectoryInfo dir = new DirectoryInfo(n.SelectedPath);? ? ? ? ? ? ? ? ? ? FileInfo[] file1 = dir.GetFiles("*.jpg");? ? ? ? ? ? ? ? ? ? foreach (FileInfo str1 in file1)? ? ? ? ? ? ? ? ? ? {? ? ? ? ? ? ? ? ? ? ? ? strfiles[i] = str1.FullName.ToString();? ? ? ? ? ? ? ? ? ? ? ? i++;? ? ? ? ? ? ? ? ? ? }? ? ? ? ? ? ? ? ? ? FileInfo[] file2 = dir.GetFiles("*.bmp");? ? ? ? ? ? ? ? ? ? foreach (FileInfo str1 in file2)? ? ? ? ? ? ? ? ? ? {? ? ? ? ? ? ? ? ? ? ? ? strfiles[i] = str1.FullName.ToString();? ? ? ? ? ? ? ? ? ? ? ? i++;? ? ? ? ? ? ? ? ? ? }? ? ? ? ? ? ? ? ? ? FileInfo[] file3 = dir.GetFiles("*.png");? ? ? ? ? ? ? ? ? ? foreach (FileInfo str1 in file3)? ? ? ? ? ? ? ? ? ? {? ? ? ? ? ? ? ? ? ? ? ? strfiles[i] = str1.FullName.ToString();? ? ? ? ? ? ? ? ? ? ? ? i++;? ? ? ? ? ? ? ? ? ? }? ? ? ? ? ? ? ? ? ? size = i;? ? ? ? ? ? ? ? ? ? this.pictureBox1.Image = System.Drawing.Image.FromFile(strfiles[k]);? ? ? ? ? ? ? ? ? ? str = strfiles[k];? ? ? ? ? ? ? ? ? ? this.SaveToolStripMenuItem.Visible = true;? ? ? ? ? ? ? ? ? ? this.FormatChangeToolStripMenuItem.Visible = true;? ? ? ? ? ? ? ? ? ? this.EditToolStripMenuItem.Visible = true;? ? ? ? ? ? ? ? }? ? ? ? ? ? ? ? catch? ? ? ? ? ? ? ? {? ? ? ? ? ? ? ? ? ? MessageBox.Show("沒(méi)有圖片文件", "警告", MessageBoxButtons.OK);? ? ? ? ? ? ? ? }? ? ? ? ? ? }? ? ? ? }? ? ? ? private void SaveToolStripMenuItem_Click(object sender, EventArgs e)//保存? ? ? ? {? ? ? ? ? ? SaveFileDialog saveFileDialog1 = new SaveFileDialog();? ? ? ? ? ? saveFileDialog1.Filter = "jpg文件(*.jpg)|*.ipg|bmp文件(*.bmp)|*.bmp|png文件(*.png)|*.png";? ? ? ? ? ? if (saveFileDialog1.ShowDialog() == DialogResult.OK)? ? ? ? ? ? {? ? ? ? ? ? ? ? this.pictureBox1.Image.Save(saveFileDialog1.FileName);? ? ? ? ? ? }? ? ? ? }? ? ? ??? ? ? ? private void GrayToolStripMenuItem_Click(object sender, EventArgs e)//灰度處理? ? ? ? {? ? ? ? ? ? try? ? ? ? ? ? {? ? ? ? ? ? ? ? Color c;? ? ? ? ? ? ? ? int red, green, blue, cl;? ? ? ? ? ? ? ? Bitmap befor = new Bitmap(pictureBox1.Image);? ? ? ? ? ? ? ? Bitmap after = new Bitmap(befor);? ? ? ? ? ? ? ? for (int i = 0; i < befor.Width; i++)? ? ? ? ? ? ? ? {? ? ? ? ? ? ? ? ? ? for (int j = 0; j < befor.Height; j++)? ? ? ? ? ? ? ? ? ? {? ? ? ? ? ? ? ? ? ? ? ? c = befor.GetPixel(i, j);? ? ? ? ? ? ? ? ? ? ? ? red = c.R;? ? ? ? ? ? ? ? ? ? ? ? green = c.G;? ? ? ? ? ? ? ? ? ? ? ? blue = c.B;? ? ? ? ? ? ? ? ? ? ? ? cl = (red + green + blue) / 3;? ? ? ? ? ? ? ? ? ? ? ? Color cc = Color.FromArgb(cl, cl, cl);? ? ? ? ? ? ? ? ? ? ? ? after.SetPixel(i, j, cc);? ? ? ? ? ? ? ? ? ? }? ? ? ? ? ? ? ? }? ? ? ? ? ? ? ? this.pictureBox1.Image = after;? ? ? ? ? ? }? ? ? ? ? ? catch? ? ? ? ? ? {? ? ? ? ? ? ? ? MessageBox.Show("未加載圖片", "警告", MessageBoxButtons.OK);? ? ? ? ? ? }? ? ? ? }? ? }}
- 1 回答
- 0 關(guān)注
- 2011 瀏覽
添加回答
舉報(bào)
0/150
提交
取消