Unity3D比较图像

时间:2015-03-09 18:07:03

标签: unity3d

我试图用第二张图片的黑色像素来查看图片的黑色像素。如何将apple.GetPixel(i,ii).grayscale转换为Color?

using UnityEngine;
using System.Collections;

public class ComparePictures : MonoBehaviour {

    public Texture2D apple;

    // Use this for initialization
    void Start () {
        int blackPixels = 0;
        int texWidht = (int) apple.width;
        int texHeight = (int) apple.height;
        for(int i = 0; i < texWidht; i++)
        {
            for(int ii = 0; ii < texHeight; ii++)
            {
                if(apple.GetPixel(i,ii) == Color.black)
                {
                    blackPixels ++;
                }
            }
        }
        print(blackPixels);
    }
}

1 个答案:

答案 0 :(得分:0)

要检查值是否为暗,请检查相应的值。这是一个方便的图像:

https://encrypted-tbn0.gstatic.com/images?q=tbn:ANd9GcSmn8p4QPwqPoJ-rFBgycXXnH2UmVCsQdZYMo3IvXF_92JIfJyUulr0r7g

var color : Color = Color (.3, .4, .6);
print(color.grayscale);

由你来决定黑暗是多么黑暗。一些代码可能是:

// Check if a color is over 80% dark
if(color.grayscale > 8.0)
    // Dark enough for me