making a white black smooth animation
-
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 { 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;
}
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 { for(int x=0; x < b.Width; ++x ) { blue = p\[0\]; green = p\[1\]; red = p\[2\]; //my changings start h
-
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 { 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;
}
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 { for(int x=0; x < b.Width; ++x ) { blue = p\[0\]; green = p\[1\]; red = p\[2\]; //my changings start h
Sajjad Izadi wrote:
can i change Red, Green and Blue colors of picture (to make it gray scale) in an other way (without using the pointers
Yes, but it would be much slower. This is the fastest way to do it. Sounds like someone else has done all the work for you so far. I'm not sure what you're asking exactly, 'the result was unsuccessful' doesn't tell us much.
Christian Graus Please read this if you don't understand the answer I've given you "also I don't think "TranslateOneToTwoBillion OneHundredAndFortySevenMillion FourHundredAndEightyThreeThousand SixHundredAndFortySeven()" is a very good choice for a function name" - SpacixOne ( offering help to someone who really needed it ) ( spaces added for the benefit of people running at < 1280x1024 )
-
Sajjad Izadi wrote:
can i change Red, Green and Blue colors of picture (to make it gray scale) in an other way (without using the pointers
Yes, but it would be much slower. This is the fastest way to do it. Sounds like someone else has done all the work for you so far. I'm not sure what you're asking exactly, 'the result was unsuccessful' doesn't tell us much.
Christian Graus Please read this if you don't understand the answer I've given you "also I don't think "TranslateOneToTwoBillion OneHundredAndFortySevenMillion FourHundredAndEightyThreeThousand SixHundredAndFortySeven()" is a very good choice for a function name" - SpacixOne ( offering help to someone who really needed it ) ( spaces added for the benefit of people running at < 1280x1024 )
i don't know how to use these two methods to make a smooth conversion of colored picture to a gray scale one in a ditinct time. yes, i myself never could guess to use such pointers to do my work. i'm learning from the friends.
-
i don't know how to use these two methods to make a smooth conversion of colored picture to a gray scale one in a ditinct time. yes, i myself never could guess to use such pointers to do my work. i'm learning from the friends.
Well, not sure why I would help you if I get a 1 vote for my trouble, but, the fact is, for bigger images, you probably can't. You'd need to create the individual frames first, THEN roll through them, for it to be smooth.
Christian Graus Please read this if you don't understand the answer I've given you "also I don't think "TranslateOneToTwoBillion OneHundredAndFortySevenMillion FourHundredAndEightyThreeThousand SixHundredAndFortySeven()" is a very good choice for a function name" - SpacixOne ( offering help to someone who really needed it ) ( spaces added for the benefit of people running at < 1280x1024 )
-
Well, not sure why I would help you if I get a 1 vote for my trouble, but, the fact is, for bigger images, you probably can't. You'd need to create the individual frames first, THEN roll through them, for it to be smooth.
Christian Graus Please read this if you don't understand the answer I've given you "also I don't think "TranslateOneToTwoBillion OneHundredAndFortySevenMillion FourHundredAndEightyThreeThousand SixHundredAndFortySeven()" is a very good choice for a function name" - SpacixOne ( offering help to someone who really needed it ) ( spaces added for the benefit of people running at < 1280x1024 )
you mean to make the frames as an *.jpg in a folder and start to play them in my form like an animation. so the new and i think main question is "how is making a half grayed picture to produce the frames"? i mean a picture which is not completely colord nor completely gray.
modified on Monday, June 9, 2008 2:04 PM
-
you mean to make the frames as an *.jpg in a folder and start to play them in my form like an animation. so the new and i think main question is "how is making a half grayed picture to produce the frames"? i mean a picture which is not completely colord nor completely gray.
modified on Monday, June 9, 2008 2:04 PM
Actually, an easier way to do all this. Create your grey image. Then draw it on top of the color one over and over with varying transparency, which you get by setting the opacity of the ImageAttributes class.
Christian Graus Please read this if you don't understand the answer I've given you "also I don't think "TranslateOneToTwoBillion OneHundredAndFortySevenMillion FourHundredAndEightyThreeThousand SixHundredAndFortySeven()" is a very good choice for a function name" - SpacixOne ( offering help to someone who really needed it ) ( spaces added for the benefit of people running at < 1280x1024 )