Compare 2 bitmaps

Hello,

I am trying to create a mini game for a school project. The goal is to trace a line thats drawn on a bitmap in photoshop.

At the end of the game i need t check how good you did this. now i use this code for checking it

for(var xcoord =0; xcoord < 1024; xcoord++)
{
    for(var ycoord = 0; ycoord < 768; ycoord++)
    {
        var col = backdrop.GetPixel(xcoord,ycoord);
        var check_color = drawing.GetPixel(xcoord,ycoord);
        if(col != Color.white && check_color == Color.red)
        {
            match++;
        }
    }
}

But unity crashes if i run the code. Is there a better way to compare the 2 bitmaps??

I can't see anything is wrong here. Yre you sure that this part crashs Unity?

Well just some hints:

  1. Make sure your variables `backdrop` and `drawing` are really of type Texture2D and they are existing (not null).
  2. Be sure you can read the pixels. Check the isReadable flag. For more information check out the script reference on `Texture3d.GetPixel`.
  3. Maybe show a bit more of your script. You can edit your question at any time to add/correct/modify your information.

MM i found out that the image wanted to check wasn't the right format. i used Auto 16 bit. bit i needed rgb 24 bit. code works fine now with no more crashes.

New revised code:

if(Input.GetMouseButton(0))
{
    for(var xcoord=Input.mousePosition.x-5 ;xcoord<Input.mousePosition.x+5 ;xcoord++)
    {
        for(var ycoord=Input.mousePosition.y-5 ;ycoord<Input.mousePosition.y+5 ;ycoord++)
        {
            var pixcolor = Color.red;

            var check_color = backdrop.GetPixel(xcoord,ycoord);
            var draw_color = drawing.GetPixel(xcoord,ycoord);
            if(check_color != Color.white && draw_color != Color.red)
            {
                match++;
            }

            drawing.SetPixel (xcoord, ycoord, pixcolor);
        }
    }
}

Checking it on the fly now, just before the painted line is drawn om the canvas. work like a charm now :)