0

我们正在尝试从上传的位图图像中读取像素,但线 aBrightness = (0.2126*aPixel[1].red) + (0.7152*aPixel[1].green) + (0.0722*aPixel[1].blue)总是给出错误提示“未知属性:未定义中的“红色””。

我们当前的脚本是:

aBitmap = selectBitMap caption:"Select a Bitmap"
Print(aBitmap.height)
Print(aBitmap.width)
aLength = aBitmap.height
aWidth = aBitmap.width

for i = 0 to (aLength - 10) by 10 do
(
for j = 0 to (aWidth - 10) by 10 do
(
    Print(i)
    Print(j)
    aPixel = getPixels aBitmap [i,j] 1
    aBrightness = (0.2126*aPixel[1].red) + (0.7152*aPixel[1].green) + (0.0722*aPixel[1].blue)
    aBox = box pos:[i,j,0] width:0.1 length:0.1 height:aBrightness
)
)

我们非常感谢有关此脚本的任何帮助。

4

2 回答 2

0

你的坐标错了。X 值先行。

它应该是

APixels = Getpixels aBitmap [j, i] 1
于 2013-11-03T21:04:25.213 回答
0

您可以在使用之前检查 aPixel 是否未定义。

aPixel = getPixels aBitmap [i,j] 1
if (aPixel == undefined) do ( format "ERROR!!! [%,%]\n" i, j to:listener; continue )

aBrightness = (0.2126*aPixel[1].red) + (0.7152*aPixel[1].green) + (0.0722*aPixel[1].blue)

这可能会帮助您确定错误在哪里。通常,函数会将“未定义”返回给变量,因此您需要检查它是否未定义。在这种情况下,一旦您修复了错误,您就可以删除这种类型的代码,因为您将消除未定义的行为。请注意,我使用了“格式”而不是“打印”,这对于仅用于少量额外代码的情况要好得多。

我看到两件可疑的事情要检查。

1) maxscript 中的大多数索引都以 1 而不是 0 开头。检查文档。

2)正如Rotem指出的那样,[x,y],而不是[y,x]

于 2013-11-06T04:58:57.547 回答