I want to compare the differences by pixels maybe to convert the images first to black and white and then to compare the pixels to see if they are not the same.
I created this class. I'm not sure if I need to change the project settings to use unsafe ?
using System;
using System.Collections.Generic;
using System.Drawing;
using System.Drawing.Imaging;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace Test
{
class ImagesComparison
{
public static void ProcessUsingLockbitsAndUnsafe(Bitmap processedBitmap)
{
unsafe
{
BitmapData bitmapData = processedBitmap.LockBits(new Rectangle(0, 0, processedBitmap.Width, processedBitmap.Height), ImageLockMode.ReadWrite, processedBitmap.PixelFormat);
int bytesPerPixel = System.Drawing.Bitmap.GetPixelFormatSize(processedBitmap.PixelFormat) / 8;
int heightInPixels = bitmapData.Height;
int widthInBytes = bitmapData.Width * bytesPerPixel;
byte* ptrFirstPixel = (byte*)bitmapData.Scan0;
for (int y = 0; y < heightInPixels; y++)
{
byte* currentLine = ptrFirstPixel + (y * bitmapData.Stride);
for (int x = 0; x < widthInBytes; x = x + bytesPerPixel)
{
int oldBlue = currentLine[x];
int oldGreen = currentLine[x + 1];
int oldRed = currentLine[x + 2];
// calculate new pixel value
currentLine[x] = (byte)oldBlue;
currentLine[x + 1] = (byte)oldGreen;
currentLine[x + 2] = (byte)oldRed;
}
}
processedBitmap.UnlockBits(bitmapData);
}
}
}
}
Then in form1
private void ComparingImages()
{
Bitmap bmp1 = new Bitmap(@"d:\comparison1.gif");
Bitmap bmp2 = new Bitmap(@"d:\comparison2.gif");
ImagesComparison.ProcessUsingLockbitsAndUnsafe(bmp1);
ImagesComparison.ProcessUsingLockbitsAndUnsafe(bmp2);
}
And using it with a button click event
private void button1_Click(object sender, EventArgs e)
{
ComparingImages();
}
but how do I make the comparison between the two gif's ? and how can I create a new image showing the differences, for example the new image will show only the differences pixels in green and red or something that will show the differences ?
For example this two images to compare between them and find if they are not the same not by size but by the content of pixels.
and