Click here to Skip to main content
16,015,973 members
Home / Discussions / C#
   

C#

 
AnswerRe: How to create an undo function in a picturebox?(Console Application,using windows form) Pin
Edmundisme9-Jun-08 11:09
Edmundisme9-Jun-08 11:09 
AnswerRe: How to create an undo function in a picturebox?(Console Application,using windows form) Pin
Christian Graus9-Jun-08 13:22
protectorChristian Graus9-Jun-08 13:22 
QuestionC# TreeView Control: How to color the nodes from the parent node to the last selected child node Pin
nikhilkardale9-Jun-08 7:35
nikhilkardale9-Jun-08 7:35 
QuestionHow to get all the shares from a machine Pin
matt23lucier9-Jun-08 6:57
matt23lucier9-Jun-08 6:57 
AnswerRe: How to get all the shares from a machine Pin
Ravi Bhavnani9-Jun-08 7:09
professionalRavi Bhavnani9-Jun-08 7:09 
GeneralRe: How to get all the shares from a machine Pin
matt23lucier9-Jun-08 7:17
matt23lucier9-Jun-08 7:17 
GeneralRe: How to get all the shares from a machine Pin
matt23lucier9-Jun-08 7:58
matt23lucier9-Jun-08 7:58 
Questionmaking a white black smooth animation Pin
Sajjad Izadi9-Jun-08 6:39
Sajjad Izadi9-Jun-08 6:39 
hi friends and excuse for this long post,

i got some idea from greeeg about making a picture white and black. the method was:

public static bool GrayScale(Bitmap b)
{
	BitmapData bmData = b.LockBits(new Rectangle(0, 0, b.Width, b.Height), ImageLockMode.ReadWrite, PixelFormat.Format24bppRgb);

	int stride = bmData.Stride;
	System.IntPtr Scan0 = bmData.Scan0;

	unsafe
	{
               	//using a pointer to point to the colors of picture
		byte * p = (byte *)(void *)Scan0;

		int nOffset = stride - b.Width*3;

		byte red, green, blue;
            
		for(int y=0;y<b.height;++y)>
		{
			for(int x=0; x < b.Width; ++x )
			{
				blue = p[0];
				green = p[1];
				red = p[2];

				//changing the colors
				p[0] = p[1] = p[2] = (byte)(.299 * red + .587 * green + .114 * blue);

				p += 3;
			}
			p += nOffset;
		}
	}

	b.UnlockBits(bmData);
	return true;
}
</b.height;++y)>


it takes a picture as the argument and processes it to make it white and black.

then, again greeeg helped me and gave a method to make picture become white and black in a defined timings (like the smooth conversion of colored screen to grayscale when you click 'Turn Off' in strat menu in windows xp):

const float transitionTime = 5000f; // 5 seconds
float normalizedTransitionTime = millsecondsSinceTransitionStart / transitionTime;

red = (byte)Lerp(normalizedTransitionTime , coloredPixelR, bwPixelR);
green = (byte)Lerp(normalizedTransitionTime , coloredPixelG, bwPixelG);
blue = (byte)Lerp(normalizedTransitionTime , coloredPixelB, bwPixelB);


and said that the Lerp method is actually works like this:

float Lerp(float amount, float value1, float value2)
{
   return value1 + (value2 - value1) * amount;
}


for conversion of a picture from colored state to gray scale in a time like 500 milliseconds i merged the above ideas (of greeeg).
so i changed the first 'GrayScale(Bitmap b)' method to this:

public static bool GrayScale(Bitmap b)
{
	BitmapData bmData = b.LockBits(new Rectangle(0, 0, b.Width, b.Height), ImageLockMode.ReadWrite, PixelFormat.Format24bppRgb);

	int stride = bmData.Stride;
	IntPtr Scan0 = bmData.Scan0;

	unsafe
	{
		byte * p = (byte *)(void *)Scan0;

		int nOffset = stride - b.Width*3
	              byte red, green, blue;
	            
		for(int y=0;y<b.height;++y)>
		{
			for(int x=0; x < b.Width; ++x )
			{
				blue = p[0];
				green = p[1];
				red = p[2];

			//my changings start here

		                p[0] = (byte)Form1.Lerp(1f, (float)p[0], (float)(.114 * blue));
  			        p[1] = (byte)Form1.Lerp(1f, (float)p[1], (float)(.587 * green));
		                p[2] = (byte)Form1.Lerp(1f, (float)p[2], (float)(.299 * red));

			//end of my changings

		    		p += 3;
			}
			p += nOffset;
		}

	}

	b.UnlockBits(bmData);
	return true;
}
</b.height;++y)>



i have just changed the poinings of second 'for'
for example 'p[0]' is as blue in 'blue = (byte)Lerp(normalizedTransitionTime , coloredPixelB, bwPixelB)'

and the result was unsuccessful
have i done a correct work till now? (ofcourse not Smile | :) )

i think the problem is in choosing the second and third arguments of 'Lerp (normalizedTransitionTime , coloredPixelR, bwPixelR)'.

finally, my questions are:
1- what should the arguments be then?

2- can i change Red, Green and Blue colors of picture (to make it gray scale) in an other way (without using the pointers in 'GrayScale(Bitmap b)')?
AnswerRe: making a white black smooth animation Pin
Christian Graus9-Jun-08 6:40
protectorChristian Graus9-Jun-08 6:40 
GeneralRe: making a white black smooth animation Pin
Sajjad Izadi9-Jun-08 6:49
Sajjad Izadi9-Jun-08 6:49 
GeneralRe: making a white black smooth animation Pin
Christian Graus9-Jun-08 7:26
protectorChristian Graus9-Jun-08 7:26 
QuestionRe: making a white black smooth animation [modified] Pin
Sajjad Izadi9-Jun-08 7:49
Sajjad Izadi9-Jun-08 7:49 
AnswerRe: making a white black smooth animation Pin
Christian Graus9-Jun-08 13:25
protectorChristian Graus9-Jun-08 13:25 
QuestionChanging IIS Settings Pin
Yourbuddypal9-Jun-08 5:52
Yourbuddypal9-Jun-08 5:52 
AnswerRe: Changing IIS Settings Pin
Yourbuddypal9-Jun-08 8:33
Yourbuddypal9-Jun-08 8:33 
QuestionNamespace? Pin
#realJSOP9-Jun-08 5:27
professional#realJSOP9-Jun-08 5:27 
AnswerRe: Namespace? Pin
Judah Gabriel Himango9-Jun-08 5:37
sponsorJudah Gabriel Himango9-Jun-08 5:37 
GeneralRe: Namespace? Pin
#realJSOP9-Jun-08 5:53
professional#realJSOP9-Jun-08 5:53 
QuestionCVS update failed Pin
humayunlalzad9-Jun-08 4:17
humayunlalzad9-Jun-08 4:17 
AnswerRe: CVS update failed Pin
benjymous9-Jun-08 5:05
benjymous9-Jun-08 5:05 
AnswerRe: CVS update failed Pin
Ashfield9-Jun-08 21:42
Ashfield9-Jun-08 21:42 
QuestionXML Writer and the ampersand Pin
ranro20069-Jun-08 3:37
ranro20069-Jun-08 3:37 
AnswerRe: XML Writer and the ampersand Pin
leppie9-Jun-08 3:45
leppie9-Jun-08 3:45 
AnswerRe: XML Writer and the ampersand Pin
PIEBALDconsult9-Jun-08 5:46
mvePIEBALDconsult9-Jun-08 5:46 
QuestionHow to execute an SQL statement from a DataSet? Pin
bouli9-Jun-08 3:29
bouli9-Jun-08 3:29 

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.