作者btovd ()
看板C_Sharp
标题[问题] 背景模型建立问题
时间Sat Jun 7 01:06:44 2008
目前我想作一个背景模型影像建立的子程式,我还算是初学者的阶段。目前进度只写到一个预览图片的程式,大致上是想要利用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