This forum contains outdated content and is available for reading only. Please contact technical support if you have any questions.

Howto change only one special color in one Selection?

Hello everybody,

is there a possibilty to change only one special color (e.g. red tones) in one Selection of an image? For example to correct red eyes ...
Or is such a implementation planned?

greets,

André
Hello,

You have two different ways to change specified channel of bitmap. The first one is to apply ChannelBalance transformation, the following code snippet extends values of red channel of the specified bitmap region:
// Source bitmap
Aurigma.GraphicsMill.Bitmap bitmap = new Aurigma.GraphicsMill.Bitmap(@"c:/Rgb24.jpg");
Aurigma.GraphicsMill.BitmapData bitmapData = bitmap.LockBits(100, 100, 100, 100);

try
{
	// Apply channel balance
	Aurigma.GraphicsMill.Transforms.ChannelBalance transform = new Aurigma.GraphicsMill.Transforms.ChannelBalance();
	transform.Levels = new float[] {0.0f, 0.0f, -0.5f};
	transform.ApplyTransform(bitmapData);
}
finally
{
	bitmap.UnlockBits(bitmapData);
}

// Save results
bitmap.Save(@"c:\1.jpg");


The second one is to manilulate channel values by hand. The following code snippet extends values of red channel of the specified bitmap region too:
// Source bitmap
Aurigma.GraphicsMill.Bitmap bitmap = new Aurigma.GraphicsMill.Bitmap(@"c:/Rgb24.jpg");
Aurigma.GraphicsMill.BitmapData bitmapData = bitmap.LockBits(100, 100, 100, 100);

try
{
	// Increase values of the second channel
	unsafe
	{
		int stride = bitmapData.Stride;
		byte *values = (byte *)bitmapData.Scan0.ToPointer();

		for(int i = 0; i < bitmapData.Height; i++)
		{
			byte *scanline = values + i * stride;

			for(int j = 0; j < bitmapData.Width; j++)
			{
				int channel = scanline[2];

				channel += 127;
				if(channel > 255)
					channel = 255;

				scanline[2] = (byte)channel;

				scanline += bitmapData.BitsPerPixel / 8;
			}
		}
	}
}
finally
{
	bitmap.UnlockBits(bitmapData);
}

// Save result
bitmap.Save(@"c:\2.jpg");


By the way we have implemented plugin for Graphics Mill for .NET for red eye removal. If you are interested in this software, please, contact us by email sales@aurigma.com.

If you have some more questions, feel free to contact us.