Rmagickeach_pixel,它是如何工作的?
我需要在 rmagick 中操作图像的每个像素。我正在 IRB(交互式红宝石)中执行此操作,这就是我所拥有的:
require 'Rmagick'
include Magick
f = Image.new(100,100)
f.display #so far so good. A 100x100 white image is displayed
f.each_pixel {|pixel, c, r| pixel.red = 0}
f.display #the image is still white. It should really be a shade of blue.
我做错了什么?
I need to manipulate each pixel of an image in rmagick. I am doing this in IRB(interactive ruby) This is what I have:
require 'Rmagick'
include Magick
f = Image.new(100,100)
f.display #so far so good. A 100x100 white image is displayed
f.each_pixel {|pixel, c, r| pixel.red = 0}
f.display #the image is still white. It should really be a shade of blue.
What am I doing wrong?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
问题是,从each_pixel 返回的数组是一个新的数据集。数据需要存储回图像。
使用 get_pixels 和 store_pixels 代替:
The thing is, the array you get back from each_pixel is a new dataset. The data needs to be stored back to the image.
Use get_pixels and store_pixels instead: