Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Getting wrong colors after an image manipulations

I am trying to XOR some values with RGB values of my image, save that image and to do back steps, to get an original image. The problem is, that I don't know why I get not clear (with some noise) image. Here is my code, and an image below:

Bitmap original = new Bitmap("D:\\img\\1.jpg");
Bitmap inp_bmp = new Bitmap("D:\\img\\1.jpg");

int width = inp_bmp.Width;
int height = inp_bmp.Height;
Color pixel;

for (int y = 0; y < height; y += 1)
{
    for (int x = 0; x < width; x += 1)
    {
        pixel = inp_bmp.GetPixel(x, y);

        int a = pixel.A;
        int r = (pixel.R ^ (1000))%256;
        int g = (pixel.G ^ (185675))%256;
        int b = (pixel.B ^ (78942))%256;
        inp_bmp.SetPixel(x, y, Color.FromArgb(a, r, g, b));


    }
}

pictureBox2.Image = inp_bmp;
pictureBox1.Image = original;
inp_bmp.Save("D:\\img\\4.jpg");

After an image has been saved, I change

Bitmap inp_bmp = new Bitmap("D:\\img\\1.jpg");

for

 Bitmap inp_bmp = new Bitmap("D:\\img\\4.jpg");

and remove

//inp_bmp.Save("D:\\img\\4.jpg");

and I get an image like

enter image description here

(left original, right - result); As you can see, I get some wrong colors at picture 4, why? All in all it is close to original, but still it's not right

like image 714
Little Fox Avatar asked Oct 20 '22 15:10

Little Fox


1 Answers

Okey, I found the problem. The problem was with saving an image.

This helped:

 inp_bmp.Save("D:\\img\\4.png", System.Drawing.Imaging.ImageFormat.Png); 
like image 196
Little Fox Avatar answered Oct 22 '22 05:10

Little Fox