是否有一种更有效的方法对BitmapData中的像素进行XOR [英] Is there a more effective way to XOR a pixel in BitmapData

查看:133
本文介绍了是否有一种更有效的方法对BitmapData中的像素进行XOR的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我使用以下代码迭代位图的数据和各个颜色字节的XOR值.我试图找到一种更有效的方法.

我希望可以将整个像素与值0xFFFFFF00的无符号整数(32位)进行XOR运算,以反转蓝色,绿色和红色像素值,但保持Alpha值不变.我已经尝试过使用unsigned int进行此操作,但没有成功.我最后每四个像素反转一次(或其他).有什么想法吗?

这是我使用的代码,效果很好,但是我如何才能对整个像素进行异或运算,而不仅仅是单独的ARGB值?

I use the following code to iterate through the data of a bitmap and XOR th value of the individual color bytes. I have tried to find a more effective way to do this.

I was hoping that it would be possible to XOR the entire pixel with for example an unsigned int (32bits) with value 0xFFFFFF00 to inverse the blue, green and red pixel values but leave the Alpha value intact. I have tried this with an unsigned int without success. I just end up with every fourth pixel inversed (or something else). Any ideas?

This is the code i use, works fine but how can i XOR the entire pixel not just the separate ARGB-Values?

byte XOR_MASK = 0xFF;
BitmapData bmpData = backBuffer.LockBits(rect, ImageLockMode.ReadWrite, pFormat);
for (int y = 0; y < bmpData.Height; y++) 
{   
	byte* row  = (byte *)bmpData.Scan0+(y*bmpData.Stride);
	for (int x = 0; x < bmpData.Width; x++) 
	{
		row[x*4]   = (byte)(row[x*4]   ^ XOR_MASK);  // Blue
		row[x*4+1] = (byte)(row[x*4+1] ^ XOR_MASK);  // Green
		row[x*4+2] = (byte)(row[x*4+2] ^ XOR_MASK);  // Red
                // Next byte Alpha value, leave intact
	}
}
// Unlock the bits.
backBuffer.UnlockBits(bmpData);

推荐答案

For (int I = 0; I < picture.width)
{
  For (int j = 0; j < picture.height; j++)
  { color C = picture.getpixel(I, j)
     Int x = C.ToArgb();
     X = X ^ key(or whatever u want to xor against the value of x)
     C = Color.FromArgb(X);
     Picture.SetPixel(I, j, C);
    }
}


这篇关于是否有一种更有效的方法对BitmapData中的像素进行XOR的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆