我试图用第二张图片的黑色像素来查看图片的黑色像素。如何将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);
}
}
答案 0 :(得分:0)
要检查值是否为暗,请检查相应的值。这是一个方便的图像:
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