【发布时间】:2011-05-23 22:06:56
【问题描述】:
我有一个 C# 方法:
public static IEnumerator getPixels(Picture picture) {
for (int x=0; x < picture.width; x++) {
for (int y=0; y < picture.height; y++) {
yield return picture.getPixel(x, y);
}
}
}
我可以在 IronPython 中这样称呼它:
for pixel in getPixels(pic):
r, g, b = getRGB(pixel)
gray = (r + g + b)/3
setRGB(pixel, gray, gray, gray)
但我不知道如何从 IronRuby 调用它:
Myro::getPixels(pic) do |pixel|
r, g, b = Myro::getRGB pixel
gray = (r + g + b)/3
Myro::setRGB(pixel, gray, gray, gray)
end
我得到的只是Graphics+<getPixels>c__Iterator0.
我需要做什么才能在 IronRuby 中实际获取每个像素并对其进行处理?
【问题讨论】:
-
我不能直接回答你的问题,但是感知灰度的计算有一个不准确之处:它应该是 rgb 和 0.3、0.59、0.11 的点积。人们对不同颜色的亮度有不同的感知。如果您希望表示颜色的感知亮度,所有这些都适用。
-
你是对的:这不是一个直接的答案。甚至不是间接答案:)人们对 RGB 亮度的感知不均也是正确的,并且 RGB 权重有许多可能的值来制作更令人愉悦的灰度图像。但这与手头的问题无关(事实上,代码制作了完美的灰度图像)。现在我需要弄清楚如何在 IronRuby 中调用生成器...
标签: c# ruby ienumerable ironruby