Click here to Skip to main content
15,887,471 members
Home / Discussions / C#
   

C#

 
GeneralRe: streaming multiple byte[] file together to get the appearance as one... Pin
zachbob16-Jul-09 7:26
zachbob16-Jul-09 7:26 
GeneralRe: streaming multiple byte[] file together to get the appearance as one... Pin
0x3c016-Jul-09 7:35
0x3c016-Jul-09 7:35 
GeneralRe: streaming multiple byte[] file together to get the appearance as one... Pin
zachbob16-Jul-09 7:22
zachbob16-Jul-09 7:22 
AnswerRe: streaming multiple byte[] file together to get the appearance as one... Pin
Mark Salsbery16-Jul-09 8:15
Mark Salsbery16-Jul-09 8:15 
QuestionImage Brightness Pin
lexx_zone16-Jul-09 6:18
lexx_zone16-Jul-09 6:18 
AnswerRe: Image Brightness Pin
Christian Graus16-Jul-09 7:06
protectorChristian Graus16-Jul-09 7:06 
Answershameless repost Pin
Luc Pattyn16-Jul-09 7:30
sitebuilderLuc Pattyn16-Jul-09 7:30 
AnswerRe: Image Brightness Pin
lexx_zone16-Jul-09 7:59
lexx_zone16-Jul-09 7:59 
I've found one cool algorithm for brightness and contrast's change.

public static bool Brightness(Bitmap b, int nBrightness)
		{
			if (nBrightness < -255 || nBrightness > 255)
				return false;

			// GDI+ still lies to us - the return format is BGR, NOT RGB.
			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;

			int nVal = 0;

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

				int nOffset = stride - b.Width*3;
				int nWidth = b.Width * 3;

				for(int y=0;y<b.Height;++y)
				{
					for(int x=0; x < nWidth; ++x )
					{
						nVal = (int) (p[0] + nBrightness);
		
						if (nVal < 0) nVal = 0;
						if (nVal > 255) nVal = 255;

						p[0] = (byte)nVal;

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

			b.UnlockBits(bmData);

			return true;
		}

		public static bool Contrast(Bitmap b, sbyte nContrast)
		{
			if (nContrast < -100) return false;
			if (nContrast >  100) return false;

			double pixel = 0, contrast = (100.0+nContrast)/100.0;

			contrast *= contrast;

			int red, green, blue;
			
			// GDI+ still lies to us - the return format is BGR, NOT RGB.
			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
			{
				byte * p = (byte *)(void *)Scan0;

				int nOffset = stride - b.Width*3;

				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];
				
						pixel = red/255.0;
						pixel -= 0.5;
						pixel *= contrast;
						pixel += 0.5;
						pixel *= 255;
						if (pixel < 0) pixel = 0;
						if (pixel > 255) pixel = 255;
						p[2] = (byte) pixel;

						pixel = green/255.0;
						pixel -= 0.5;
						pixel *= contrast;
						pixel += 0.5;
						pixel *= 255;
						if (pixel < 0) pixel = 0;
						if (pixel > 255) pixel = 255;
						p[1] = (byte) pixel;

						pixel = blue/255.0;
						pixel -= 0.5;
						pixel *= contrast;
						pixel += 0.5;
						pixel *= 255;
						if (pixel < 0) pixel = 0;
						if (pixel > 255) pixel = 255;
						p[0] = (byte) pixel;					

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

			b.UnlockBits(bmData);

			return true;
		}


This is 'pixel per pixel' algorithm with unsafe code which gives you a really great performance even for big images.
QuestionFile Size Monitoring [modified] Pin
See_Sharp16-Jul-09 5:48
See_Sharp16-Jul-09 5:48 
AnswerRe: File Size Monitoring Pin
DaveyM6916-Jul-09 6:31
professionalDaveyM6916-Jul-09 6:31 
GeneralRe: File Size Monitoring Pin
See_Sharp16-Jul-09 7:31
See_Sharp16-Jul-09 7:31 
QuestionGenerics and Properties.Settings.Default ... Pin
Jammer16-Jul-09 5:25
Jammer16-Jul-09 5:25 
Question[Message Deleted] Pin
Member 311244716-Jul-09 5:15
Member 311244716-Jul-09 5:15 
AnswerRe: How to mark points on a windows from by mouse click.(c#.net) Pin
DaveyM6916-Jul-09 5:23
professionalDaveyM6916-Jul-09 5:23 
GeneralRe: How to mark points on a windows from by mouse click.(c#.net) Pin
Member 311244716-Jul-09 6:11
Member 311244716-Jul-09 6:11 
GeneralRe: How to mark points on a windows from by mouse click.(c#.net) Pin
dan!sh 16-Jul-09 6:19
professional dan!sh 16-Jul-09 6:19 
GeneralRe: How to mark points on a windows from by mouse click.(c#.net) Pin
DaveyM6916-Jul-09 6:24
professionalDaveyM6916-Jul-09 6:24 
QuestionGeting user defined attributes from external DLL with dependencies. Pin
Member 360506816-Jul-09 5:15
Member 360506816-Jul-09 5:15 
QuestionNationalInstrument Pin
peishen8816-Jul-09 5:01
peishen8816-Jul-09 5:01 
AnswerRe: NationalInstrument Pin
Rajesh R Subramanian16-Jul-09 5:08
professionalRajesh R Subramanian16-Jul-09 5:08 
GeneralRe: NationalInstrument Pin
peishen8816-Jul-09 6:05
peishen8816-Jul-09 6:05 
QuestionUsing 64 bit DLL Pin
musefan16-Jul-09 4:39
musefan16-Jul-09 4:39 
AnswerRe: Using 64 bit DLL Pin
Nagy Vilmos16-Jul-09 5:18
professionalNagy Vilmos16-Jul-09 5:18 
GeneralRe: Using 64 bit DLL Pin
musefan16-Jul-09 7:16
musefan16-Jul-09 7:16 
AnswerRe: Using 64 bit DLL [modified] Pin
dan!sh 16-Jul-09 5:30
professional dan!sh 16-Jul-09 5:30 

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.