Bitmap bit1 = new Bitmap( bmpimg , width , height );
Bitmap bit2 = new Bitmap( bmp , width , height );
Bitmap bmpresult = new Bitmap( width , height );
BitmapData data1 = bit1.LockBits( new Rectangle( 0 , 0 , bit1.Width , bit1.Height ) , ImageLockMode.ReadWrite , PixelFormat.Format24bppRgb );
BitmapData data2 = bit2.LockBits( new Rectangle( 0 , 0 , bit2.Width , bit2.Height ) , ImageLockMode.ReadWrite , PixelFormat.Format24bppRgb );
BitmapData data3 = bmpresult.LockBits( new Rectangle( 0 , 0 , bmpresult.Width , bmpresult.Height ) , ImageLockMode.ReadWrite , PixelFormat.Format24bppRgb );
unsafe
{
int remain1 = data1.Stride - data1.Width * 3;
int remain2 = data2.Stride - data2.Width * 3;
int remain3 = data3.Stride - data3.Width * 3;
byte* ptr1 = ( byte* )data1.Scan0;
byte* ptr2 = ( byte* )data2.Scan0;
byte* ptr3 = ( byte* )data3.Scan0;
for( int i = 0 ; i < height ; i ++ )
{
for( int j = 0 ; j < width * 3 ; j ++ )
{
ptr3[ 0 ] = ( byte ) ( XOR_Operator( ptr1[ 0 ] , ptr2[ 0 ] ) );
ptr1 ++;
ptr2 ++;
ptr3 ++;
}
ptr1 += remain1;
ptr2 += remain2;
ptr3 += remain3;
}
}
bit1.UnlockBits( data1 );
bit2.UnlockBits( data2 );
bmpresult.UnlockBits( data3 );
return bmpresult;
}
is it necessary to get remain for data objects
The stride is the width of a single row of pixels (a scan line), rounded up to a four-byte boundary. If the stride is positive, the bitmap is top-down. If the stride is negative, the bitmap is bottom-up.
The stride is the number of bytes from one row of pixels in memory to the next row of pixels in memory. Stride is also called pitch. If padding bytes are present, the stride is wider than the width of the image, as shown in the following illustration.
Stride is an open-source C# game engine for realistic rendering and VR. The engine is highly modular and aims at giving game makers more flexibility in their development. It can be used to create not only games but can also serve as a foundation for apps and tools.
Stride is there due to hardware requirements that have unfortunately leaked through to the API layer.
It is important because Windows drivers sometimes require that scanlines (rows in the image) be memory aligned. That is why they are sometimes larger than they would strictly need to be.
See for example this MSDN article DIBs and Their Use.
Every scanline is DWORD-aligned. The scanline is buffered to alignment; the buffering is not necessarily 0.
Your handling seems to be sufficient.
Stride is the number of bytes your code must iterate past to reach the next vertical pixel.
This may be different from the image's width * pixel size if hardware requires a width of a certain multiple.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With