Setting RGB color values of an image

Aug 25, 2014 at 2:41 PM
I am using .NET. I need to replace the RGB values on an image with different values

for example
R:128, G:118 B:118 to R:100, G:105, B:110

Can you please help me to do this or Guide a way

Any help is greatly appreciated
prasanth
Aug 25, 2014 at 3:53 PM
Edited Aug 25, 2014 at 3:53 PM
I tried the following code but WritablePixelCollection Write() is not updating the image at all
Also i tried writing the image to physical drive again but not working
using (MagickImage image = new MagickImage(@"E:\Development\DOTNET\PCXEditor\RGBEditor\18975253ee.pcx"))
        {

                WritablePixelCollection p = image.GetWritablePixels();
                foreach (Pixel pp in p)
                {

                    Pixel pc = new Pixel(1, 1, 4);

                    Color c = pp.ToColor();
                    if (c.R == 128)
                        //r = 100;

                        pc.SetChannel(0, 100);

                    if (c.G == 118)
                        //g = 105;
                        pc.SetChannel(1, 105);
                    if (c.B == 118)
                        //b = 110;
                        pc.SetChannel(2, 110);

                    p.Set(pc);


                    //pc = null;
                }

                MessageBox.Show(p.GetPixel(1, 1).ToColor().R.ToString());   // the value has changed already still here its fine
                p.Write(); // this is not working

                  // image.Write(@"E:\Development\DOTNET\PCXEditor\RGBEditor\1897525311-changed.pcx");

        }
Coordinator
Aug 25, 2014 at 5:01 PM
You should use the Opaque method of MagickImage to do this. You could use the WritablePixelcollection but the Opaque method will be much faster. Your code only changes the pixel at 1x1 so that is probably why you think it is not working.

This will get you the result you are expecting:
using (MagickImage image = new MagickImage(@"E:\Development\DOTNET\PCXEditor\RGBEditor\18975253ee.pcx"))
{
  MagickColor target = new MagickColor(128, 118, 118);
  MagickColor fill = new MagickColor(100, 105, 110);

  image.Opaque(target, fill);

  image.Write(@"E:\Development\DOTNET\PCXEditor\RGBEditor\1897525311-changed.pcx");
}
Note: This example only works with the Q8 version of Magick.NET because that version has pixels in the 0-255 range
Aug 27, 2014 at 12:54 PM
That was great. Thanks a ton

I am done with the coding but when i tried to release the product to a different machine. its not working in any machine ,the application breaks before its start
I have installed .NET 4.0: Visual C++ Redistributable for Visual Studio 2012 (x86 or x64)

Do you have any documentation for deployment. Can you please guide me for a proper release
Coordinator
Aug 27, 2014 at 1:01 PM
Are you using the .NET 2.0 or the .NET 4.0 release of Magick.NET? And do you get an exception when the application crashes?
Aug 27, 2014 at 1:05 PM
I have downloaded Magick.NET-7.0.0.0002-Q8-AnyCPU-net40-client.zip
Aug 27, 2014 at 1:08 PM
Apart from

Visual C++ Redistributable for Visual Studio
.NET 4.0: Visual C++ Redistributable for Visual Studio 2012 (x86 or x64)
.NET 2.0: Visual C++ Redistributable for Visual Studio 2008 (x86 or x64)
Do i need to register or install anything else.

I have copied my release folder to the client machine
Aug 27, 2014 at 1:39 PM
I am getting the error

Failed to Load embedded Assembly : Could not load file or assembly Magic.NET -Q8 -x86.dll or one or more of its dependencies The specified module could not be found.

But i have referenced Magick.NET.AnyCPU.dll any idea why its showing the error
Coordinator
Aug 27, 2014 at 2:28 PM
You only need to install '.NET 4.0: Visual C++ Redistributable for Visual Studio 2012 (x86 or x64)'. The specified module could not be found error message is probably happening because your server first needs a reboot. Have you rebooted the machine after the installation?
Aug 28, 2014 at 10:55 AM
Everything is fine now. Thanks a ton for your kind support.