EFileTahi-A
Contributor
Can someone please try to figure out what is happening here? I'm trying to apply the Multiply filter, similar to the one Photoshop uses by crossing the RGB values between two images. I'm not a pointer* guy at all and most of the code was taken from internet so I can't really say what is wrong.
The function is currently working partially, that is, it applies the filter only over a third of the image from top to bottom on the left side.
I really wish I could understand a bit more of how this function actually works. The filter seems to play instantaneously against the 10sec it takes doing it with GDI+.
Thanks
The function is currently working partially, that is, it applies the filter only over a third of the image from top to bottom on the left side.
Code:
private void button2_Click(object sender, EventArgs e)
{
Bitmap srcA = (Bitmap)this.lbl_map.Image;
Bitmap srcB = (Bitmap)this.lbl_paper.Image;
BitmapData dataA = SetImageToProcess(srcA, new Rectangle(0, 0, 1280, 800));
BitmapData dataB = SetImageToProcess(srcB, new Rectangle(0, 0, 1280, 800));
int width = dataA.Width;
int height = dataA.Height;
int offset = dataA.Stride - width;
unsafe
{
byte* ptrA = (byte*)dataA.Scan0;
byte* ptrB = (byte*)dataB.Scan0;
for (int y = 0; y < height; y++)
{
for (int x = 0; x < width; x++, ++ptrA, ++ptrB)
{
int result = (ptrB[0] * ptrA[0]) / 255;
ptrA[0] = (byte)result > (byte)255 ? (byte)255 : (byte)result;
}
ptrA += offset;
ptrB += offset;
}
}
srcA.UnlockBits(dataA);
srcB.UnlockBits(dataB);
this.BackgroundImage = srcA;
}
static public BitmapData SetImageToProcess(Bitmap image, Rectangle roi)
{
if (image != null)
return image.LockBits(
roi,
ImageLockMode.ReadWrite,
image.PixelFormat);
return null;
}
I really wish I could understand a bit more of how this function actually works. The filter seems to play instantaneously against the 10sec it takes doing it with GDI+.
Thanks