[問題] 背景模型建立問題

看板C_Sharp (C#)作者時間18年前 (2008/06/07 01:06), 編輯推噓0(000)
留言0則, 0人參與, 最新討論串1/1
目前我想作一個背景模型影像建立的子程式,我還算是初學者的階段。目前進度只寫到一個預覽圖片的程式,大致上是想要利用FolderBrowserDialog載入一個圖片的資料夾,然後利用資料夾裡的圖片作出一個背景影像(就是將這些圖片中共同的像素值讀出來,然後弄出一張影像圖)。 目前的問題是在於怎麼把載入的資料夾利用open打開?然後將取得裡面的圖片。還有背景模型建立的原理要怎麼做呢? 以上是我的問題,感謝大大的指教。 using System; using System.Collections.Generic; using System.ComponentModel; using System.Data; using System.Drawing; using System.Text; using System.Windows.Forms; using System.IO; namespace 背景模型建立 { public partial class Form1 : Form { public Form1() { InitializeComponent(); } private void Form1_Load(object sender, EventArgs e) { textBox1.Text = "尚未選取檔案"; listBox1.Items.Add("尚未載入目錄檔案"); } /*******************************儲?檔案*************************************************************/ /********************************************************************************************/ private void button3_Click(object sender, EventArgs e) { if (pictureBox2.Image != null) { SaveFileDialog saveFileDialog1 = new SaveFileDialog(); saveFileDialog1.Filter = "JPG(*.jpg)|*.jpg|" + "BMP(*.bmp)|*.bmp"; saveFileDialog1.FileName = ""; if (saveFileDialog1.ShowDialog() == DialogResult.OK) { pictureBox2.Image.Save(saveFileDialog1.FileName); } } else if (pictureBox2.Image == null) { if (MessageBox.Show("尚未載入圖片,無法存檔", "系統訊息", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes) { listBox1.Items.Clear(); FolderBrowserDialog folderBrowserDialog1 = new FolderBrowserDialog(); folderBrowserDialog1.Description = "選擇檔案夾"; folderBrowserDialog1.RootFolder = Environment.SpecialFolder.Desktop; if (folderBrowserDialog1.ShowDialog() == DialogResult.OK) { mPath = folderBrowserDialog1.SelectedPath; System.IO.DirectoryInfo mDir = new System.IO.DirectoryInfo(mPath); textBox1.Text = mPath; int a = 0; foreach (System.IO.FileInfo sFile in mDir.GetFiles("*.jpg")) { listBox1.Items.Add(sFile.Name); a++; } label1.Text = a.ToString(); } } else if (MessageBox.Show("離開系統", "系統訊息", MessageBoxButtons.OK, MessageBoxIcon.Stop) == DialogResult.OK) { Application.Exit(); } } } //******************************************************************************************************************************** /****************************************離開程式************************************************************************/ private void button4_Click(object sender, EventArgs e) { if (MessageBox.Show("Exit Application?", "系統訊息", MessageBoxButtons.YesNo, MessageBoxIcon.Information) == DialogResult.Yes) { Application.Exit(); } } /********************************************************************************************************************************/ /*************************************************開啟檔案***********************************************************************/ string mPath; //File[] files; //DirectoryInfo mDir; int a; private void button1_Click(object sender, EventArgs e) { L1: listBox1.Items.Clear(); FolderBrowserDialog folderBrowserDialog1 = new FolderBrowserDialog(); folderBrowserDialog1.Description = "選擇檔案夾"; folderBrowserDialog1.RootFolder = Environment.SpecialFolder.Desktop; if (folderBrowserDialog1.ShowDialog() == DialogResult.OK) { mPath = folderBrowserDialog1.SelectedPath; System.IO.DirectoryInfo mDir = new System.IO.DirectoryInfo(mPath); textBox1.Text = mPath; a = 0; foreach (System.IO.FileInfo sFile in mDir.GetFiles("*.jpg")) { listBox1.Items.Add(sFile.Name); a++; } label1.Text = a.ToString(); } else if (MessageBox.Show("是否重新載入檔案", "系統訊息", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes) { goto L1; } } /******************************************預覽影像檔*******************************************************/ private void listBox1_MouseClick(object sender, System.Windows.Forms.MouseEventArgs e) { if (listBox1.SelectedItem != null) { pictureBox1.Image = Image.FromFile(mPath + @"\\" + listBox1.SelectedItem); pictureBox1.SizeMode = PictureBoxSizeMode.Zoom; } else { FolderBrowserDialog folderBrowserDialog1 = new FolderBrowserDialog(); folderBrowserDialog1.Description = "選擇檔案夾"; folderBrowserDialog1.RootFolder = Environment.SpecialFolder.Desktop; if (folderBrowserDialog1.ShowDialog() == DialogResult.OK) { mPath = folderBrowserDialog1.SelectedPath; System.IO.DirectoryInfo mDir = new System.IO.DirectoryInfo(mPath); textBox1.Text = mPath; a = 0; foreach (System.IO.FileInfo sFile in mDir.GetFiles("*.jpg")) { listBox1.Items.Add(sFile.FullName); a++; } label1.Text = a.ToString(); } } } /*******************************listBox item 變色**************************************************/ private void listBox1_DrawItem(object sender, System.Windows.Forms.DrawItemEventArgs e) { listBox1.DrawMode = DrawMode.OwnerDrawVariable; e.DrawBackground(); Brush myBrush =Brushes.Black; switch (e.Index % 2) { case 0: myBrush = Brushes.Red; break; case 1: myBrush = Brushes.Gray; break; } e.Graphics.DrawString(listBox1.Items[e.Index].ToString(), e.Font,myBrush,e.Bounds,StringFormat.GenericDefault); e.DrawFocusRectangle(); } } } -- ※ 發信站: 批踢踢實業坊(ptt.cc) ◆ From: 61.221.84.73
文章代碼(AID): #18IMwbeC (C_Sharp)
文章代碼(AID): #18IMwbeC (C_Sharp)