- Home /
how compare 2 imagens
I want to take one image and compare another. example: I will take a screenshot and I want to compare if the image that was taken is the same one that I have or if it has the same drawing in the 2 images
Comment
How are you storing your images?
Are they Textures? Or are you trying to compare image files (.png, .jpg, etc)?
Answer by toddisarockstar · Oct 16, 2017 at 01:35 AM
you can skip the first half of my code if you are not reading from hard drive. otherwise this should work for standalone or PC builds to read files saved to a drive with a screenshot:
public Texture2D[] imgs;
// path1 and path2 are the file path to the two images to compair
public string path1,path2;
int i,x,y;
bool nomatch;
void Start(){
imgs = new Texture2D[2];
imgs [0] = new Texture2D (1, 1);
imgs [1] = new Texture2D (1, 1);
imgs [0].LoadImage (File.ReadAllBytes (path1));
imgs [1].LoadImage (File.ReadAllBytes (path2));
y = imgs [0].height;
x = imgs [0].width;
if(x!=imgs[1].width||y!=imgs[1].height){nomatch=true;}
else{while(x>0){x--;
y=imgs[0].height;
while(y>0){y--;
if(imgs[0].GetPixel(x,y)!=imgs[1].GetPixel(x,y)){
nomatch=true;
}}}}
if(nomatch){print("images are differnt");}
else{print("images are the same");}}
this needs to be at the very top of your script:
using System.IO;