Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/301.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C#位图通过异或改变像素颜色_C#_Ffmpeg_Bitmap_Byte_Drawing - Fatal编程技术网

C#位图通过异或改变像素颜色

C#位图通过异或改变像素颜色,c#,ffmpeg,bitmap,byte,drawing,C#,Ffmpeg,Bitmap,Byte,Drawing,我尝试使用RGB的XOR来更改RGB颜色 示例: =>如果某个像素上的R值为5=101//Color pcolor=image.GetPixel(j,k) =>然后对一些字节101^11111111=11111010执行异或运算 //R[x,w]=(字节)(R[x,w]^mykey[0]) =>并用结果R=11111 010=250替换R //SetPixel(y,z,Color.FromArgb(A[y,z],R[y,z],G[y,z],B[y,z]); 但问题是,如果我再次读取结果帧,我之

我尝试使用RGB的XOR来更改RGB颜色
示例:
=>如果某个像素上的R值为5=101
//Color pcolor=image.GetPixel(j,k)

=>然后对一些字节101^11111111=11111010执行异或运算
//R[x,w]=(字节)(R[x,w]^mykey[0])

=>并用结果R=11111 010=250替换R
//SetPixel(y,z,Color.FromArgb(A[y,z],R[y,z],G[y,z],B[y,z]);

但问题是,如果我再次读取结果帧,我之前更改的R值不是250

using Accord.Video.FFMPEG;


publicstaticvoidmyfunc(VideoFileReader读取器、VideoFileWriter编写器)
{
字节[]mykey={0xff,0x55,0x00};
位图图像=新位图(reader.Width、reader.Height、PixelFormat.Format24bppRgb);

对于(int i=0;i请发布您正在使用的实际代码。您发布的代码不会编译。@itsme86是我的实际代码。我使用ffmpeg C#library读取一帧视频。我可以判断它不是您的实际代码,因为您说它不会改变颜色,这意味着它会运行,这意味着它会编译。除非您以某种方式添加了一个属性y将
Lenght
调用到字节数组,它将无法编译。如果您不发布实际的代码,我们可能会在实际不存在的代码问题上花费时间。@itsme86好的,对不起,我错过了这一部分。让我们把
x%mykey.Length
(我写了
mykey.Lenght
关于这个问题,对不起)到0。我尝试黑白视频。R的第一个值为0,XOR为255。处理完成后,结果将为255。我读取的帧结果R值更改为251。writer.WriteVideoFrame(图像)
函数是否正在更改颜色值?。
VideoFileReader reader = new VideoFileReader();
reader.Open(@"E:\Video\Sample.MP4");
VideoFileWriter writer = new VideoFileWriter();
writer.Open(@"E:\Video\Result.MP4", reader.Width, reader.Height, reader.FrameRate, VideoCodec.MPEG4);
MyFunc(reader, writer)
public static void Myfunc(VideoFileReader reader, VideoFileWriter writer)
    {
    byte[] mykey = { 0xff, 0x55, 0x00 };
    Bitmap image = new Bitmap(reader.Width, reader.Height, PixelFormat.Format24bppRgb);
    for (int i = 0; i<reader.FrameCount; i++)
    {
        Bitmap videoFrame = reader.ReadVideoFrame();
        image = videoFrame;
        byte[,] A = new byte[reader.Width, reader.Height];
        byte[,] R = new byte[reader.Width, reader.Height];
        byte[,] G = new byte[reader.Width, reader.Height];
        byte[,] B = new byte[reader.Width, reader.Height];
        for (int j = 0; j<reader.Width; j++)
        {
            for (int k = 0; k<reader.Height; k++)
            {
                Color pcolor = image.GetPixel(j, k);
                A[j, k] = pcolor.A;
                R[j, k] = pcolor.R;
                G[j, k] = pcolor.G;
                B[j, k] = pcolor.B;
            }
        }

        for (int x = 0; x<reader.Width; x++)
        {
            for (int w = 0; w<reader.Height; w++)
            {
                R[x, w] = (byte) (R[x, w] ^ mykey[0]);
                G[x, w] = (byte) (G[x, w] ^ mykey[0]);
                B[x, w] = (byte) (B[x, w] ^ mykey[0]);
           }
        }

        for (int y = 0; y<reader.Width; y++)
        {
            for (int z = 0; z<reader.Height; z++)
            {
                image.SetPixel(y, z, Color.FromArgb(A[y, z], R[y, z], G[y, z], B[y, z]));
            }
        }

        writer.WriteVideoFrame(image);
        videoFrame.Dispose();
    }
}