Click here to Skip to main content
15,895,011 members
Home / Discussions / C#
   

C#

 
AnswerRe: Need GUI help, to child or not child? Pin
Jon Hulatt19-Jun-07 10:18
Jon Hulatt19-Jun-07 10:18 
Questionattach serial command to button [modified] Pin
dirtylarry19-Jun-07 6:06
dirtylarry19-Jun-07 6:06 
AnswerRe: attach serial command to button Pin
dirtylarry20-Jun-07 12:57
dirtylarry20-Jun-07 12:57 
Questionno value returned Pin
arkiboys19-Jun-07 6:05
arkiboys19-Jun-07 6:05 
AnswerRe: no value returned Pin
Jimmanuel19-Jun-07 6:54
Jimmanuel19-Jun-07 6:54 
GeneralSorted collection with alternate sort key Pin
Brady Kelly19-Jun-07 5:24
Brady Kelly19-Jun-07 5:24 
GeneralRe: Sorted collection with alternate sort key Pin
originSH19-Jun-07 5:44
originSH19-Jun-07 5:44 
QuestionGrey Scale Image error?? Pin
Software_Specialist19-Jun-07 5:04
Software_Specialist19-Jun-07 5:04 
Hi below is the code for conversion to grey scale image.
But i am getting exception at first line of the GrayScale function that
Object reference not set to an instance of an object.
I am using VS2005.

Any help would be appreciated....
Thanks

<br />
<br />
private Bitmap b;<br />
<br />
private void GrayScaleMenuItem_Click(object sender, System.EventArgs e)<br />
		{<br />
			if(GrayScale(b))<br />
			this.Invalidate();<br />
		}<br />
<br />
<br />
public static bool GrayScale(Bitmap b)<br />
		{<br />
		BitmapData bmData = b.LockBits(new Rectangle(0, 0, b.Width, b.Height), ImageLockMode.ReadWrite, PixelFormat.Format24bppRgb);<br />
<br />
			int stride = bmData.Stride;<br />
			System.IntPtr Scan0 = bmData.Scan0;<br />
<br />
			unsafe<br />
			{<br />
				byte * p = (byte *)(void *)Scan0;<br />
<br />
				int nOffset = stride - b.Width*3;<br />
<br />
				byte red, green, blue;<br />
	<br />
				for(int y=0;y<b.Height;++y)<br />
				{<br />
					for(int x=0; x < b.Width; ++x )<br />
					{<br />
						blue = p[0];<br />
						green = p[1];<br />
						red = p[2];<br />
<br />
						p[0] = p[1] = p[2] = (byte)(.299 * red + .587 * green + .114 * blue);<br />
<br />
						p += 3;<br />
					}<br />
					p += nOffset;<br />
				}<br />
			}<br />
<br />
			b.UnlockBits(bmData);<br />
<br />
			return true;<br />
		}

AnswerRe: Grey Scale Image error?? Pin
Giorgi Dalakishvili19-Jun-07 5:20
mentorGiorgi Dalakishvili19-Jun-07 5:20 
GeneralRe: Grey Scale Image error?? Pin
Software_Specialist19-Jun-07 5:30
Software_Specialist19-Jun-07 5:30 
GeneralRe: Grey Scale Image error?? Pin
Luc Pattyn19-Jun-07 5:40
sitebuilderLuc Pattyn19-Jun-07 5:40 
GeneralRe: Grey Scale Image error?? Pin
Software_Specialist19-Jun-07 5:57
Software_Specialist19-Jun-07 5:57 
GeneralRe: Grey Scale Image error?? Pin
Luc Pattyn19-Jun-07 6:08
sitebuilderLuc Pattyn19-Jun-07 6:08 
GeneralRe: Grey Scale Image error?? Pin
Software_Specialist21-Jun-07 4:46
Software_Specialist21-Jun-07 4:46 
GeneralRe: Grey Scale Image error?? Pin
Luc Pattyn21-Jun-07 5:02
sitebuilderLuc Pattyn21-Jun-07 5:02 
GeneralRe: Grey Scale Image error?? Pin
Software_Specialist21-Jun-07 5:07
Software_Specialist21-Jun-07 5:07 
GeneralRe: Grey Scale Image error?? Pin
Luc Pattyn21-Jun-07 5:22
sitebuilderLuc Pattyn21-Jun-07 5:22 
GeneralRe: Grey Scale Image error?? Pin
Software_Specialist21-Jun-07 5:30
Software_Specialist21-Jun-07 5:30 
GeneralRe: Grey Scale Image error?? Pin
Luc Pattyn21-Jun-07 5:48
sitebuilderLuc Pattyn21-Jun-07 5:48 
GeneralRe: Grey Scale Image error?? Pin
Software_Specialist21-Jun-07 6:26
Software_Specialist21-Jun-07 6:26 
GeneralRe: Grey Scale Image error?? Pin
Amar Chaudhary19-Jun-07 6:25
Amar Chaudhary19-Jun-07 6:25 
QuestionAdding event handler to custom control Pin
berghain19-Jun-07 4:56
berghain19-Jun-07 4:56 
AnswerRe: Adding event handler to custom control Pin
Manas Bhardwaj19-Jun-07 5:03
professionalManas Bhardwaj19-Jun-07 5:03 
QuestionAvoid trailing while dragging control Pin
sinosoidal19-Jun-07 4:49
sinosoidal19-Jun-07 4:49 
AnswerRe: Avoid trailing while dragging control Pin
Alaric_19-Jun-07 5:08
professionalAlaric_19-Jun-07 5:08 

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.