我尝试使用RGB的XOR更改RGB颜色。
例如:
=>如果某个像素上的R值为5 = 101左右//颜色pcolor = image.GetPixel(j,k);
=>然后用一些字节101 ^ 11111111 = 11111010执行XOR
// R [x,w] =(byte)(R [x,w] ^ mykey [0]);
=>并将R替换为R = 11111010 = 250
//image.SetPixel(y,z,Color.FromArgb(A [y,z],R [y,z],G [y,z],B [y,z]));
但问题是如果我再次读取结果框架,我之前更改的R值不是250。
using Accord.Video.FFMPEG;
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();
}
}