Bitmap: Using Using Using Using Using Using Using Using Using Namespace Public Partial Class Static Public
Bitmap: Using Using Using Using Using Using Using Using Using Namespace Public Partial Class Static Public
using
using
using
using
using
using
using
using
using
System;
System.Collections.Generic;
System.ComponentModel;
System.Data;
System.Drawing;
System.Text;
System.Windows.Forms;
System.IO;
AviFile;
namespace Digital_Video_Bitmap
{
public partial class Bitmap : Form
{
static System.Drawing.Bitmap currentbit;
public Bitmap()
{
InitializeComponent();
}
ImageHandler imageHandler = new ImageHandler();
private void button1_Click(object sender, EventArgs e)
{
String fileName = GetFileName("Videos (*.avi)|*.avi;*.mpe;*.mpeg");
if (fileName != null)
{
txtAviFileName.Text = fileName;
ShowFrame();
}
AviManager aviManager = new AviManager(txtAviFileName.Text, true);
VideoStream stream = aviManager.GetVideoStream();
stream.GetFrameOpen();
txtReportCopy.Text = txtFileNames.Text = String.Empty;
string q = Application.ExecutablePath.ToString();
string q1 = q.Substring(0, q.LastIndexOf("\\")) + "\\testdata\\";
string path = @q1;
string[] filePaths = Directory.GetFiles(@q1);
foreach (string filePath in filePaths)
File.Delete(filePath);
for (int n = 0; n < stream.CountFrames; n++)
{
stream.ExportBitmap(n, path + n.ToString() + ".bmp");
//txtReportCopy.Text += n + ".bmp finished...\r\n";
//txtFileNames.Text += path + n + ".bmp\r\n";
}
stream.GetFrameClose();
aviManager.Close();
}
private void ShowFrame()
{
if (System.IO.File.Exists(txtAviFileName.Text))
{
try
{
AviManager aviManager = new AviManager(txtAviFileName.Text, true);
VideoStream aviStream = aviManager.GetVideoStream();
aviStream.GetFrameOpen();
System.Drawing.Bitmap bmp =
aviStream.GetBitmap(Convert.ToInt32(numPosition.Value));
picFrame.Image = (System.Drawing.Bitmap)bmp;
aviStream.GetFrameClose();
aviManager.Close();
}
catch (Exception ex)
{
MessageBox.Show(ex.ToString());
}
}
}
private String GetFileName(String filter)
{
OpenFileDialog dlg = new OpenFileDialog();
dlg.Filter = filter;
dlg.RestoreDirectory = true;
if (txtAviFileName.Text.Length > 0)
{
dlg.InitialDirectory = GetCurrentFilePath();
}
if (dlg.ShowDialog(this) == DialogResult.OK)
{
return dlg.FileName;
}
else
{
return null;
}
}
private String GetCurrentFilePath()
{
return txtAviFileName.Text.Substring(0, txtAviFileName.Text.LastIndexOf("\\") + 1);
}
private void button1_Click_1(object sender, EventArgs e)
{
string q = Application.ExecutablePath.ToString();
string imagepath = q.Substring(0, q.LastIndexOf("\\")) + "\\modifiedbitmap\\0.bmp";
string newvideo = q.Substring(0, q.LastIndexOf("\\")) + "\\testdata\\new.avi"; //load the
first image
string imagedirectory = q.Substring(0, q.LastIndexOf("\\")) + "\\modifiedbitmap\\";
System.Drawing.Bitmap bitmap = (System.Drawing.Bitmap)Image.FromFile(@imagepath);
//create a new AVI file
AviManager aviManager = new AviManager(@newvideo, false); //create a new AVI file
VideoStream aviStream = aviManager.AddVideoStream(true, 10, bitmap);
int count = 0;
DirectoryInfo di = new DirectoryInfo(@imagedirectory);
VideoStream newStream;
AviManager newManager = aviStream.DecompressToNewFile(newName, compress, out
newStream);
aviManager.Close(); //close compressed file
newManager.Close(); //save and close un-/re-compressed file
}
private void Bitmap_Load(object sender, EventArgs e)
{
}
private void btnbrightness_Click(object sender, EventArgs e)
{
string q = Application.ExecutablePath.ToString();
string imagepath = q.Substring(0, q.LastIndexOf("\\")) + "\\testdata\\";
DirectoryInfo d = new DirectoryInfo(imagepath);
FileInfo[] totfiles = d.GetFiles("*.bmp");
for (int i = 0; i <= totfiles.Length - 1; i++)
{
string imagepath1 = q.Substring(0, q.LastIndexOf("\\")) + "\\testdata\\" + i + ".bmp";
currentbit = (System.Drawing.Bitmap)Image.FromFile(imagepath1).Clone();
System.Drawing.Bitmap temp =
imageHandler.SetBrightness(Convert.ToInt32(textBox1.Text), currentbit, i);
System.Drawing.Bitmap bitsave = (System.Drawing.Bitmap)temp.Clone();
bitsave.Save(q.Substring(0, q.LastIndexOf("\\")) + "\\modifiedbitmap\\" + i + ".bmp");
this.Invalidate();
}
}
public int BrightnessValue
{
get
{
return trackBar1.Value;
}
//set
//{
// txtBrightnessValue.Text = value.ToString();
//}
}
private void btncontrast_Click(object sender, EventArgs e)
{
string q = Application.ExecutablePath.ToString();
string imagepath = q.Substring(0, q.LastIndexOf("\\")) + "\\testdata\\";
DirectoryInfo d = new DirectoryInfo(imagepath);
FileInfo[] totfiles = d.GetFiles("*.bmp");
for (int i = 0; i <= totfiles.Length - 1; i++)
{
string imagepath1 = q.Substring(0, q.LastIndexOf("\\")) + "\\testdata\\" + i + ".bmp";
currentbit = (System.Drawing.Bitmap)Image.FromFile(imagepath1).Clone();
System.Drawing.Bitmap currentimage =
imageHandler.SetContrast(Convert.ToInt32(textBox1.Text), currentbit, i);
currentimage.Save(q.Substring(0, q.LastIndexOf("\\")) + "\\modifiedbitmap\\" + i +
".bmp");
this.Invalidate();
}
}
private void btninvert_Click(object sender, EventArgs e)
{
string q = Application.ExecutablePath.ToString();
string imagepath = q.Substring(0, q.LastIndexOf("\\")) + "\\testdata\\";
DirectoryInfo d = new DirectoryInfo(imagepath);
FileInfo[] totfiles = d.GetFiles("*.bmp");
for (int i = 0; i <= totfiles.Length - 1; i++)
{
string imagepath1 = q.Substring(0, q.LastIndexOf("\\")) + "\\testdata\\" + i + ".bmp";
currentbit = (System.Drawing.Bitmap)Image.FromFile(imagepath1);
System.Drawing.Bitmap currentbitmap = currentbit.Clone(new Rectangle(0, 0,
currentbit.Size.Width, currentbit.Size.Height), System.Drawing.Imaging.PixelFormat.DontCare);
System.Drawing.Bitmap newbitmap = imageHandler.SetInvert(currentbitmap);
//System.Drawing.Bitmap currentimage =
imageHandler.SetContrast(Convert.ToInt32(textBox1.Text), currentbit, i);
".bmp");
}
}
private void btngrayscale_Click(object sender, EventArgs e)
{
string q = Application.ExecutablePath.ToString();
string imagepath = q.Substring(0, q.LastIndexOf("\\")) + "\\testdata\\";
DirectoryInfo d = new DirectoryInfo(imagepath);
FileInfo[] totfiles = d.GetFiles("*.bmp");
for (int i = 0; i <= totfiles.Length - 1; i++)
{
string imagepath1 = q.Substring(0, q.LastIndexOf("\\")) + "\\testdata\\" + i + ".bmp";
currentbit = (System.Drawing.Bitmap)Image.FromFile(imagepath1);
System.Drawing.Bitmap currentbitmap = currentbit.Clone(new Rectangle(0, 0,
currentbit.Size.Width, currentbit.Size.Height), System.Drawing.Imaging.PixelFormat.DontCare);
System.Drawing.Bitmap newbitmap = imageHandler.SetGrayscale(currentbitmap);
".bmp");
}
}
private void txtgamma_Click(object sender, EventArgs e)
{
GammaForm gFrm = new GammaForm();
gFrm.RedComponent = gFrm.GreenComponent = gFrm.BlueComponent = 0;
if (gFrm.ShowDialog() == DialogResult.OK)
{
string q = Application.ExecutablePath.ToString();
string imagepath = q.Substring(0, q.LastIndexOf("\\")) + "\\testdata\\";
DirectoryInfo d = new DirectoryInfo(imagepath);
FileInfo[] totfiles = d.GetFiles("*.bmp");
for (int i = 0; i <= totfiles.Length - 1; i++)
{
string imagepath1 = q.Substring(0, q.LastIndexOf("\\")) + "\\testdata\\" + i + ".bmp";
currentbit = (System.Drawing.Bitmap)Image.FromFile(imagepath1);
System.Drawing.Bitmap currentbitmap = currentbit.Clone(new Rectangle(0, 0,
currentbit.Size.Width, currentbit.Size.Height), System.Drawing.Imaging.PixelFormat.DontCare);
System.Drawing.Bitmap newbitmap =
imageHandler.SetGamma(gFrm.RedComponent, gFrm.GreenComponent, gFrm.BlueComponent,
currentbitmap);
newbitmap.Save(q.Substring(0, q.LastIndexOf("\\")) + "\\modifiedbitmap\\" + i +
".bmp");
}
}
this.Invalidate();
}
Brightness
using
using
using
using
using
using
using
System;
System.Collections.Generic;
System.ComponentModel;
System.Data;
System.Drawing;
System.Text;
System.Windows.Forms;
namespace Digital_Video_Bitmap
{
public partial class Brightness : Form
{
public Brightness()
{
InitializeComponent();
btnOK.DialogResult = DialogResult.OK;
btnCancel.DialogResult = DialogResult.Cancel;
}
public int BrightnessValue
{
get
{
numRate.Value = 0;
return Convert.ToInt32(numRate.Value);
}
set { numRate.Value = Convert.ToInt32(value.ToString()); }
}
private void btnOK_Click(object sender, EventArgs e)
{
}
COMPARE VIDEO
using
using
using
using
using
using
using
using
System;
System.Collections.Generic;
System.ComponentModel;
System.Data;
System.Drawing;
System.Text;
System.Windows.Forms;
System.IO;
namespace Digital_Video_Bitmap
{
public partial class comparevideo : Form
{
public comparevideo()
{
InitializeComponent();
}
string newvideo;
string q;
string imagepath;
private void comparevideo_Load(object sender, EventArgs e)
{
q = Application.ExecutablePath.ToString();
imagepath = q.Substring(0, q.LastIndexOf("\\"));
newvideo = q.Substring(0, q.LastIndexOf("\\")) + "\\testdata\\new.avi";
DirectoryInfo d = new DirectoryInfo(imagepath);
FileInfo[] f = d.GetFiles("*.avi");
string r=d.ToString();
string r1 = f.GetValue(0).ToString();
axWindowsMediaPlayer1.URL = r + "\\" + r1;
axWindowsMediaPlayer2.URL = newvideo;
}
private void btnplay_Click(object sender, EventArgs e)
{
newvideo = q.Substring(0, q.LastIndexOf("\\")) + "\\testdata\\new.avi";
imagepath = q.Substring(0, q.LastIndexOf("\\")) + "\\testdata\\0.bmp";
q = Application.ExecutablePath.ToString();
DirectoryInfo d = new DirectoryInfo(imagepath);
FileInfo[] f = d.GetFiles(".avi");
axWindowsMediaPlayer1.URL = f[0].ToString();
axWindowsMediaPlayer2.URL = newvideo;
}
private void pictureBox1_Click(object sender, EventArgs e)
{
this.Hide();
}
private void axWindowsMediaPlayer1_Enter(object sender, EventArgs e)
{
}
}
CONTRAST
using
using
using
using
using
using
using
System;
System.Collections.Generic;
System.ComponentModel;
System.Data;
System.Drawing;
System.Text;
System.Windows.Forms;
namespace Digital_Video_Bitmap
{
public partial class ContrastForm : Form
{
public ContrastForm()
{
InitializeComponent();
btnOK.DialogResult = DialogResult.OK;
btnCancel.DialogResult = DialogResult.Cancel;
}
set { nudcontrast.Value =Convert.ToInt32(value.ToString()); }
PROGRESS BAR
using
using
using
using
using
using
using
System;
System.Collections.Generic;
System.ComponentModel;
System.Data;
System.Drawing;
System.Text;
System.Windows.Forms;
namespace Digital_Video_Bitmap
{
public partial class fmProgress : Form
{
private bool m_Cancel = false;
public bool Cancel
{
get { return m_Cancel; }
}
public fmProgress()
{
InitializeComponent();
}
private void fmProgress_FormClosing(object sender, FormClosingEventArgs e)
{
// If the user clicks the X or hit's Alt+F4 consider this a cancel
// but don't let the form close, otherwise we can't check the Cancel
// property because the form will be null.
m_Cancel = true;
e.Cancel = true;
}
private void bnCancel_Click(object sender, EventArgs e)
{
}
FRAME RATE
using
using
using
using
using
using
using
System;
System.Collections.Generic;
System.ComponentModel;
System.Data;
System.Drawing;
System.Text;
System.Windows.Forms;
namespace Digital_Video_Bitmap
{
public partial class FrameRateForm : Form
{
private double rate = 0;
public FrameRateForm()
{
InitializeComponent();
}
public double Rate
{
get { return rate; }
}
private void btnOK_Click(object sender, EventArgs e)
{
rate = (double)numRate.Value;
this.DialogResult = DialogResult.OK;
this.Close();
}
private void btnCancel_Click(object sender, EventArgs e)
{
this.DialogResult = DialogResult.Cancel;
this.Close();
}
}
}
GAMMA
using
using
using
using
using
using
using
System;
System.Collections.Generic;
System.ComponentModel;
System.Data;
System.Drawing;
System.Text;
System.Windows.Forms;
namespace Digital_Video_Bitmap
{
public partial class GammaForm : Form
{
public GammaForm()
{
InitializeComponent();
btnOK.DialogResult = DialogResult.OK;
btnCancel.DialogResult = DialogResult.Cancel;
}
public double RedComponent
{
get
{
if (string.IsNullOrEmpty(txtRedValue.Text))
txtRedValue.Text = "0";
return Convert.ToDouble(txtRedValue.Text);
}
set { txtRedValue.Text = value.ToString(); }
}
public double GreenComponent
{
get
{
if (string.IsNullOrEmpty(txtGreenValue.Text))
txtGreenValue.Text = "0";
return Convert.ToDouble(txtGreenValue.Text);
}
set { txtGreenValue.Text = value.ToString(); }
}
public double BlueComponent
{
get
{
if (string.IsNullOrEmpty(txtBlueValue.Text))
txtBlueValue.Text = "0";
return Convert.ToDouble(txtBlueValue.Text);
}
set { txtBlueValue.Text = value.ToString(); }
}
private void GammaForm_Load(object sender, EventArgs e)
{
}
VIDEO
using
using
using
using
using
using
using
using
using
using
using
System;
System.Collections.Generic;
System.ComponentModel;
System.Data;
System.Drawing;
System.Text;
System.Windows.Forms;
System.Runtime.InteropServices;
System.Threading;
System.IO;
AviFile;
namespace Digital_Video_Bitmap
{
public partial class Main : Form
{
ImageHandler imageHandler = new ImageHandler();
static System.Drawing.Bitmap currentbit;
string videopath, fileName, imagepath, q;
private fmProgress m_fmProgress = null;
private BackgroundWorker m_AsyncWorker = new BackgroundWorker();
[DllImportAttribute("user32.dll")]
public static extern int SendMessage(IntPtr hWnd, int Msg, int wParam, int lParam);
[DllImportAttribute("user32.dll")]
public static extern bool ReleaseCapture();
[DllImport("Gdi32.dll", EntryPoint = "CreateRoundRectRgn")]
private static extern IntPtr CreateRoundRectRgn
(
int nLeftRect, // x-coordinate of upper-left corner
int nTopRect, // y-coordinate of upper-left corner
int nRightRect, // x-coordinate of lower-right corner
int nBottomRect, // y-coordinate of lower-right corner
int nWidthEllipse, // height of ellipse
int nHeightEllipse // width of ellipse
);
public Main()
{
InitializeComponent();
Region = System.Drawing.Region.FromHrgn(CreateRoundRectRgn(6, 6, Width - 10, Height
+ 30, 20, 20));
m_AsyncWorker.WorkerReportsProgress = true;
m_AsyncWorker.WorkerSupportsCancellation = true;
}
private void ShowFrame()
{
if (System.IO.File.Exists(txtAviFileName.Text))
{
try
System.Drawing.Bitmap bmp =
aviStream.GetBitmap(Convert.ToInt32(numPosition.Value));
// picFrame.Image = (System.Drawing.Bitmap)bmp;
aviStream.GetFrameClose();
aviManager.Close();
}
catch (Exception ex)
{
MessageBox.Show(ex.ToString());
}
}
}
private String GetFileName(String filter)
{
OpenFileDialog dlg = new OpenFileDialog();
dlg.Filter = filter;
dlg.RestoreDirectory = true;
if (txtAviFileName.Text.Length > 0)
{
dlg.InitialDirectory = GetCurrentFilePath();
}
if (dlg.ShowDialog(this) == DialogResult.OK)
{
return dlg.FileName;
}
else
{
return null;
}
}
private String GetCurrentFilePath()
{
return txtAviFileName.Text.Substring(0, txtAviFileName.Text.LastIndexOf("\\") + 1);
}
#region Synchronous BackgroundWorker Thread
private void btncreateframe_Click(object sender, EventArgs e)
{
BackgroundWorker bw = new BackgroundWorker(); // Create a background thread
bw.DoWork += new DoWorkEventHandler(bw_DoWork);
bw.RunWorkerCompleted += new
RunWorkerCompletedEventHandler(bw_RunWorkerCompleted);
m_fmProgress = new fmProgress(); // Create a progress form on the UI thread
bw.RunWorkerAsync(); // Kick off the Async thread
m_fmProgress.ShowDialog(this); // Lock up the UI with this modal progress form.
m_fmProgress = null;
btncreatevideo.Enabled = true;
MessageBox.Show("Processing cancelled.");
return;
}
}
private void bw_RunWorkerCompleted(object sender, RunWorkerCompletedEventArgs e)
{
runworkercompleted(e);
}
#endregion
private void btncreatevideo_Click(object sender, EventArgs e)
{
BackgroundWorker bwcreatevideo = new BackgroundWorker(); // Create a background
thread
bwcreatevideo.DoWork += new DoWorkEventHandler(bwcreatevideo_DoWork);
bwcreatevideo.RunWorkerCompleted += new
RunWorkerCompletedEventHandler(bwcreatevideo_RunWorkerCompleted);
m_fmProgress = new fmProgress(); // Create a progress form on the UI thread
bwcreatevideo.RunWorkerAsync(); // Kick off the Async thread
m_fmProgress.ShowDialog(this); // Lock up the UI with this modal progress form.
m_fmProgress = null;
//if (folderBrowserDialog1.ShowDialog() == DialogResult.OK)
// File.Copy(@"C:\Directory1\Excel1.xls", @"C:\Directory2\Excel1.xls");
//else if (folderBrowserDialog1.ShowDialog() == DialogResult.Cancel) { }
}
private void bwcreatevideo_DoWork(object sender, DoWorkEventArgs e)
{
string q = Application.ExecutablePath.ToString();
string imagepath = q.Substring(0, q.LastIndexOf("\\")) + "\\testdata\\0.bmp";
string newvideo = q.Substring(0, q.LastIndexOf("\\")) + "\\testdata\\new.avi"; //load the
first image
string imagedirectory = q.Substring(0, q.LastIndexOf("\\")) + "\\modifiedbitmap\\";
System.Drawing.Bitmap bitmap = (System.Drawing.Bitmap)Image.FromFile(@imagepath);
//create a new AVI file
AviManager aviManager = new AviManager(@newvideo, false); //create a new AVI file
VideoStream aviStream = aviManager.AddVideoStream(true, 15, bitmap);
DirectoryInfo di = new DirectoryInfo(@imagedirectory);
FileInfo[] fiArr = di.GetFiles("*.bmp");
string imagedirectory1 = q.Substring(0, q.LastIndexOf("\\")) + "\\modifiedbitmap\\";
DirectoryInfo di1 = new DirectoryInfo(@imagedirectory1);
//foreach (FileInfo f in di.GetFiles())
// f.Delete();
for (int n = 0; n < di1.GetFiles().Length - 1; n++)
{
bitmap = (System.Drawing.Bitmap)System.Drawing.Bitmap.FromFile(q.Substring(0,
q.LastIndexOf("\\")) + "\\modifiedbitmap\\" + n + ".bmp");
aviStream.AddFrame(bitmap);
bitmap.Dispose();
m_fmProgress.lblDescription.Invoke(
(MethodInvoker)delegate()
{
m_fmProgress.lblDescription.Text = "Processing file " + n.ToString() + " of " +
di1.GetFiles().Length.ToString();
m_fmProgress.progressBar1.Value = Convert.ToInt32(n * (100.0 /
(di1.GetFiles().Length)));
}
);
if (m_fmProgress.Cancel)
{
e.Cancel = true;
return;
}
}
aviManager.Close();
}
private void bwcreatevideo_RunWorkerCompleted(object sender,
RunWorkerCompletedEventArgs e)
{
runworkercompleted(e);
}
private void compareVideoToolStripMenuItem_Click(object sender, EventArgs e)
{
comparevideo video = new comparevideo();
video.ShowDialog();
}
private void toolStripMenuItem1_Click(object sender, EventArgs e)
{
BackgroundWorker bwbright = new BackgroundWorker(); // Create a background thread
bwbright.DoWork += new DoWorkEventHandler(bwbright_DoWork);
bwbright.RunWorkerCompleted += new
RunWorkerCompletedEventHandler(bwbright_RunWorkerCompleted);
m_fmProgress = new fmProgress(); // Create a progress form on the UI thread
bwbright.RunWorkerAsync(); // Kick off the Async thread
m_fmProgress.ShowDialog(this); // Lock up the UI with this modal progress form.
m_fmProgress = null;
}
private void bwbright_DoWork(object sender, DoWorkEventArgs e)
{
Brightness bright = new Brightness();
if (bright.ShowDialog() == DialogResult.OK)
{
string q = Application.ExecutablePath.ToString();
string imagepath = q.Substring(0, q.LastIndexOf("\\")) + "\\testdata\\";
DirectoryInfo d = new DirectoryInfo(imagepath);
FileInfo[] totfiles = d.GetFiles("*.bmp");
for (int i = 0; i <= totfiles.Length - 1; i++)
{
string imagepath1 = q.Substring(0, q.LastIndexOf("\\")) + "\\testdata\\" + i + ".bmp";
currentbit = (System.Drawing.Bitmap)Image.FromFile(imagepath1).Clone();
System.Drawing.Bitmap temp =
imageHandler.SetBrightness((bright.BrightnessValue), currentbit, i);
System.Drawing.Bitmap bitsave = (System.Drawing.Bitmap)temp.Clone();
".bmp");
m_fmProgress.lblDescription.Invoke(
(MethodInvoker)delegate()
{
m_fmProgress.lblDescription.Text = "Processing file " + i.ToString() + " of " +
totfiles.Length.ToString();
m_fmProgress.progressBar1.Value = Convert.ToInt32(i * (100.0 /
(totfiles.Length)));
}
);
if (m_fmProgress.Cancel)
{
e.Cancel = true;
return;
}
}
}
}
private void bwbright_RunWorkerCompleted(object sender, RunWorkerCompletedEventArgs
e)
{
runworkercompleted(e);
}
private void bwcontrast_DoWork(object sender, DoWorkEventArgs e)
{
ContrastForm cFrm = new ContrastForm();
if (cFrm.ShowDialog() == DialogResult.OK)
{
string q = Application.ExecutablePath.ToString();
string imagepath = q.Substring(0, q.LastIndexOf("\\")) + "\\testdata\\";
DirectoryInfo d = new DirectoryInfo(imagepath);
FileInfo[] totfiles = d.GetFiles("*.bmp");
for (int i = 0; i <= totfiles.Length - 1; i++)
{
string imagepath1 = q.Substring(0, q.LastIndexOf("\\")) + "\\testdata\\" + i + ".bmp";
currentbit = (System.Drawing.Bitmap)Image.FromFile(imagepath1).Clone();
System.Drawing.Bitmap currentimage =
imageHandler.SetContrast(cFrm.ContrastValue, currentbit, i);
currentimage.Save(q.Substring(0, q.LastIndexOf("\\")) + "\\modifiedbitmap\\" + i +
".bmp");
this.Invalidate();
m_fmProgress.lblDescription.Invoke(
(MethodInvoker)delegate()
{
m_fmProgress.lblDescription.Text = "Processing file " + i.ToString() + " of " +
totfiles.Length.ToString();
m_fmProgress.progressBar1.Value = Convert.ToInt32(i * (100.0 /
(totfiles.Length)));
}
);
if (m_fmProgress.Cancel)
{
e.Cancel = true;
return;
}
}
private void bwcontrast_RunWorkerCompleted(object sender,
RunWorkerCompletedEventArgs e)
{
runworkercompleted(e);
}
private void toolStripMenuItem2_Click(object sender, EventArgs e)
{
BackgroundWorker bwcontrast = new BackgroundWorker(); // Create a background thread
bwcontrast.DoWork += new DoWorkEventHandler(bwcontrast_DoWork);
bwcontrast.RunWorkerCompleted += new
RunWorkerCompletedEventHandler(bwcontrast_RunWorkerCompleted);
m_fmProgress = new fmProgress(); // Create a progress form on the UI thread
bwcontrast.RunWorkerAsync(); // Kick off the Async thread
m_fmProgress.ShowDialog(this); // Lock up the UI with this modal progress form.
m_fmProgress = null;
}
private void bwinvert_DoWork(object sender, DoWorkEventArgs e)
{
string q = Application.ExecutablePath.ToString();
string imagepath = q.Substring(0, q.LastIndexOf("\\")) + "\\testdata\\";
DirectoryInfo d = new DirectoryInfo(imagepath);
FileInfo[] totfiles = d.GetFiles("*.bmp");
for (int i = 0; i <= totfiles.Length - 1; i++)
{
string imagepath1 = q.Substring(0, q.LastIndexOf("\\")) + "\\testdata\\" + i + ".bmp";
currentbit = (System.Drawing.Bitmap)Image.FromFile(imagepath1);
System.Drawing.Bitmap currentbitmap = currentbit.Clone(new Rectangle(0, 0,
currentbit.Size.Width, currentbit.Size.Height), System.Drawing.Imaging.PixelFormat.DontCare);
System.Drawing.Bitmap newbitmap = imageHandler.SetInvert(currentbitmap);
//System.Drawing.Bitmap currentimage =
imageHandler.SetContrast(Convert.ToInt32(textBox1.Text), currentbit, i);
newbitmap.Save(q.Substring(0, q.LastIndexOf("\\")) + "\\modifiedbitmap\\" + i +
".bmp");
this.Invalidate();
m_fmProgress.lblDescription.Invoke(
(MethodInvoker)delegate()
{
m_fmProgress.lblDescription.Text = "Processing file " + i.ToString() + " of " +
totfiles.Length.ToString();
m_fmProgress.progressBar1.Value = Convert.ToInt32(i * (100.0 /
(totfiles.Length)));
}
);
if (m_fmProgress.Cancel)
{
e.Cancel = true;
return;
}
}
private void bwinvert_RunWorkerCompleted(object sender, RunWorkerCompletedEventArgs
e)
runworkercompleted(e);
}
private void toolStripMenuItem3_Click(object sender, EventArgs e)
{
BackgroundWorker bwinvert = new BackgroundWorker(); // Create a background thread
bwinvert.DoWork += new DoWorkEventHandler(bwinvert_DoWork);
bwinvert.RunWorkerCompleted += new
RunWorkerCompletedEventHandler(bwinvert_RunWorkerCompleted);
m_fmProgress = new fmProgress(); // Create a progress form on the UI thread
bwinvert.RunWorkerAsync(); // Kick off the Async thread
this.Invalidate();
m_fmProgress.lblDescription.Invoke(
(MethodInvoker)delegate()
{
m_fmProgress.lblDescription.Text = "Processing file " + i.ToString() + " of " +
totfiles.Length.ToString();
m_fmProgress.progressBar1.Value = Convert.ToInt32(i * (100.0 /
(totfiles.Length)));
}
);
if (m_fmProgress.Cancel)
{
e.Cancel = true;
return;
}
}
}
private void bwgray_RunWorkerCompleted(object sender, RunWorkerCompletedEventArgs e)
{
runworkercompleted(e);
}
private void tsmigrayscale_Click(object sender, EventArgs e)
{
BackgroundWorker bwgray = new BackgroundWorker(); // Create a background thread
bwgray.DoWork += new DoWorkEventHandler(bwgray_DoWork);
bwgray.RunWorkerCompleted += new
RunWorkerCompletedEventHandler(bwgray_RunWorkerCompleted);
m_fmProgress = new fmProgress(); // Create a progress form on the UI thread
bwgray.RunWorkerAsync(); // Kick off the Async thread
m_fmProgress.ShowDialog(this); // Lock up the UI with this modal progress form.
m_fmProgress = null;
}
private void bwgamma_DoWork(object sender, DoWorkEventArgs e)
{
GammaForm gFrm = new GammaForm();
gFrm.RedComponent = gFrm.GreenComponent = gFrm.BlueComponent = 0;
if (gFrm.ShowDialog() == DialogResult.OK)
{
string q = Application.ExecutablePath.ToString();
string imagepath = q.Substring(0, q.LastIndexOf("\\")) + "\\testdata\\";
DirectoryInfo d = new DirectoryInfo(imagepath);
FileInfo[] totfiles = d.GetFiles("*.bmp");
for (int i = 0; i <= totfiles.Length - 1; i++)
{
string imagepath1 = q.Substring(0, q.LastIndexOf("\\")) + "\\testdata\\" + i + ".bmp";
currentbit = (System.Drawing.Bitmap)Image.FromFile(imagepath1);
System.Drawing.Bitmap currentbitmap = currentbit.Clone(new Rectangle(0, 0,
currentbit.Size.Width, currentbit.Size.Height), System.Drawing.Imaging.PixelFormat.DontCare);
System.Drawing.Bitmap newbitmap =
imageHandler.SetGamma(gFrm.RedComponent, gFrm.GreenComponent, gFrm.BlueComponent,
currentbitmap);
".bmp");
m_fmProgress.lblDescription.Invoke(
(MethodInvoker)delegate()
{
m_fmProgress.lblDescription.Text = "Processing file " + i.ToString() + " of " +
totfiles.Length.ToString();
m_fmProgress.progressBar1.Value = Convert.ToInt32(i * (100.0 / (totfiles.Length)));
}
);
if (m_fmProgress.Cancel)
{
e.Cancel = true;
return;
}
}
}
}
private void bwgamma_RunWorkerCompleted(object sender,
RunWorkerCompletedEventArgs e)
{
runworkercompleted(e);
}
private void tsmigamma_Click(object sender, EventArgs e)
{
BackgroundWorker bwgamma = new BackgroundWorker(); // Create a background thread
bwgamma.DoWork += new DoWorkEventHandler(bwgamma_DoWork);
bwgamma.RunWorkerCompleted += new
RunWorkerCompletedEventHandler(bwgamma_RunWorkerCompleted);
m_fmProgress = new fmProgress(); // Create a progress form on the UI thread
bwgamma.RunWorkerAsync(); // Kick off the Async thread
m_fmProgress.ShowDialog(this); // Lock up the UI with this modal progress form.
m_fmProgress = null;
}
private void pictureBox1_Click(object sender, EventArgs e)
{
this.WindowState = FormWindowState.Minimized;
}
private void pictureBox2_Click(object sender, EventArgs e)
{
this.Close();
}
private void button1_Click(object sender, EventArgs e)
{
//framecmp fcmp = new framecmp();
//fcmp.Show();
}
private void Main_Load(object sender, EventArgs e)
{
}
private void button1_Click_1(object sender, EventArgs e)
{
}