And this the source code which I have written so far. But this source code still has some mistakes. I am still unable to stitch the image but my source code can subtract between the two images and merge them together.
The problems are :
1. The images are only "merged" together but they are not stitched together.
2. The size of the output images are still same. I need to get the size of the output image base on the size of the stitched image. So in other words the size of the image should change after I apply the result.
public Bitmap Substraction(Bitmap bmpA, Bitmap bmpB)
{
BitmapData bmpData_A = bmpA.LockBits(new Rectangle(0, 0, bmpA.Width, bmpA.Height), ImageLockMode.ReadWrite, PixelFormat.Format24bppRgb);
BitmapData bmpData_B = bmpB.LockBits(new Rectangle(0, 0, bmpB.Width, bmpB.Height), ImageLockMode.ReadWrite, PixelFormat.Format24bppRgb);
int width_A = bmpData_A.Width;
int width_B = bmpData_B.Width;
int height_A = bmpData_A.Height;
int height_B = bmpData_B.Height;
bmpA.UnlockBits(bmpData_A);
bmpB.UnlockBits(bmpData_B);
Bitmap input_img1 = new Bitmap(bmpA, width_A, height_A);
Bitmap input_img2 = new Bitmap(bmpB, width_B, height_B);
int width_output = width_A + width_B;
int height_output = height_A + width_B;
Bitmap output_image = new Bitmap(width_A, height_B);
BitmapData bmpdata1 = input_img1.LockBits(new Rectangle(0, 0, input_img1.Width, input_img1.Height), ImageLockMode.ReadWrite, PixelFormat.Format24bppRgb);
BitmapData bmpdata2 = input_img2.LockBits(new Rectangle(0, 0, input_img2.Width, input_img2.Height), ImageLockMode.ReadWrite, PixelFormat.Format24bppRgb);
BitmapData bmpoutput = output_image.LockBits(new Rectangle(0, 0, output_image.Width, output_image.Height), ImageLockMode.ReadWrite, PixelFormat.Format24bppRgb);
unsafe
{
int ptr1 = bmpdata1.Stride - bmpdata1.Width * 3;
int ptr2 = bmpdata2.Stride - bmpdata2.Width * 3;
int ptr3 = bmpoutput.Stride - bmpoutput.Width * 3;
byte* p1 = (byte*)bmpdata1.Scan0;
byte* p2 = (byte*)bmpdata2.Scan0;
byte* p3 = (byte*)bmpoutput.Scan0;
for (int y = 0; y < height_A; y++)
{
for (int x = 0; x < width_A * 3; x++)
{
p3[0] = (byte)(Math.Abs(p2[0] - p1[0]));
p1++;
p2++;
p3++;
}
p1 += ptr1;
p2 += ptr2;
p3 += ptr3;
}
}
input_img1.UnlockBits(bmpdata1);
input_img2.UnlockBits(bmpdata2);
output_image.UnlockBits(bmpoutput);
return output_image;
}
As always, Thank you so much for your comments and advices. I appreciate it a lot.