Click here to Skip to main content
15,903,385 members
Home / Discussions / C#
   

C#

 
AnswerA Sink captures events Pin
Ennis Ray Lynch, Jr.20-Jul-06 3:46
Ennis Ray Lynch, Jr.20-Jul-06 3:46 
Question"What's this" Help Pin
trupci20-Jul-06 3:29
trupci20-Jul-06 3:29 
AnswerRe: Record Sound Pin
Corinna John20-Jul-06 3:15
Corinna John20-Jul-06 3:15 
QuestionGreyscale an Image the easy way... Pin
matthias s.20-Jul-06 2:35
matthias s.20-Jul-06 2:35 
AnswerRe: Greyscale an Image the easy way... Pin
BigAndy20-Jul-06 2:57
BigAndy20-Jul-06 2:57 
GeneralRe: Greyscale an Image the easy way... Pin
matthias s.20-Jul-06 3:34
matthias s.20-Jul-06 3:34 
GeneralBitmap is an Image object Pin
Ennis Ray Lynch, Jr.20-Jul-06 3:42
Ennis Ray Lynch, Jr.20-Jul-06 3:42 
GeneralRe: Greyscale an Image the easy way... Pin
BigAndy20-Jul-06 3:47
BigAndy20-Jul-06 3:47 
How's this?

private void Form1_Load(object sender, System.EventArgs e)<br />
{<br />
	OpenFileDialog dlg = new OpenFileDialog();<br />
	dlg.Filter="Image files (*.BMP, *.JPG, *.GIF)|*.bmp;*.jpg;*.gif";<br />
	if(dlg.ShowDialog()==DialogResult.OK)<br />
	{<br />
		Image colourImage = Image.FromFile(dlg.FileName);<br />
		Image greyscaleImage = GreyscaleImage(colourImage);<br />
<br />
		//Do stuff with the images here<br />
<br />
		//Clean up<br />
		colourImage.Dispose();<br />
		greyscaleImage.Dispose();<br />
	}<br />
}<br />
<br />
private Image GreyscaleImage(Image img)<br />
{<br />
	Bitmap bm = new Bitmap(img.Width, img.Height);<br />
	Graphics g = Graphics.FromImage(bm);<br />
<br />
	ColorMatrix cm = new ColorMatrix(new float[][]{ new float[]{0.5f,0.5f,0.5f,0,0},<br />
														new float[]{0.5f,0.5f,0.5f,0,0},<br />
														new float[]{0.5f,0.5f,0.5f,0,0},<br />
														new float[]{0,0,0,1,0,0},<br />
														new float[]{0,0,0,0,1,0},<br />
														new float[]{0,0,0,0,0,1}});<br />
<br />
	ImageAttributes ia = new ImageAttributes();<br />
	ia.SetColorMatrix(cm);<br />
	g.DrawImage(img,new Rectangle(0,0,img.Width,img.Height),0,0,img.Width,img.Height,GraphicsUnit.Pixel,ia);<br />
	g.Dispose();<br />
<br />
	return (Image)bm;<br />
}

GeneralRe: Greyscale an Image the easy way... Pin
matthias s.20-Jul-06 3:53
matthias s.20-Jul-06 3:53 
AnswerIm not an imaging expert Pin
Ennis Ray Lynch, Jr.20-Jul-06 3:09
Ennis Ray Lynch, Jr.20-Jul-06 3:09 
QuestionMultithreading in C# Pin
k_dasaprakash20-Jul-06 2:08
k_dasaprakash20-Jul-06 2:08 
AnswerRe: Multithreading in C# Pin
Ennis Ray Lynch, Jr.20-Jul-06 3:12
Ennis Ray Lynch, Jr.20-Jul-06 3:12 
Questionstring to a command [modified] Pin
Schimaera20-Jul-06 2:01
Schimaera20-Jul-06 2:01 
AnswerRe: string to a command Pin
stancrm20-Jul-06 2:04
stancrm20-Jul-06 2:04 
AnswerRe: string to a command Pin
Ravi Bhavnani20-Jul-06 2:04
professionalRavi Bhavnani20-Jul-06 2:04 
AnswerRe: string to a command Pin
Colin Angus Mackay20-Jul-06 2:09
Colin Angus Mackay20-Jul-06 2:09 
GeneralRe: string to a command Pin
Schimaera20-Jul-06 2:16
Schimaera20-Jul-06 2:16 
AnswerRe: string to a command Pin
Ravi Bhavnani20-Jul-06 2:20
professionalRavi Bhavnani20-Jul-06 2:20 
GeneralRe: string to a command Pin
Schimaera20-Jul-06 2:24
Schimaera20-Jul-06 2:24 
GeneralRe: string to a command Pin
Schimaera20-Jul-06 2:44
Schimaera20-Jul-06 2:44 
GeneralRe: string to a command Pin
J4amieC20-Jul-06 2:52
J4amieC20-Jul-06 2:52 
GeneralRe: string to a command Pin
Schimaera20-Jul-06 2:57
Schimaera20-Jul-06 2:57 
GeneralRe: string to a command Pin
Schimaera20-Jul-06 3:24
Schimaera20-Jul-06 3:24 
GeneralRe: string to a command [modified] Pin
J4amieC20-Jul-06 3:48
J4amieC20-Jul-06 3:48 
GeneralRe: string to a command Pin
Josh Smith20-Jul-06 4:25
Josh Smith20-Jul-06 4:25 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.