用ChunkyPNG将多个图像“条”组合成一个图像

问题描述:

如何将多个(本例中为10)图像“条”(所有等宽)组合成一个图像与ChunkyPNG?用ChunkyPNG将多个图像“条”组合成一个图像

现在,我将所有这些图像条存储在一个数组中,并且在某些时候我将不得不根据像素数据来安排它们。这里是我的代码是这样的:

require 'chunky_png' 

image = ChunkyPNG::Image.from_file('input.png') 

width = image.dimension.width 
currentWidth = 0 
strips = [] 

20.times do 
    image2 = image.crop(currentWidth, 0, 32, 359) 
    strips << image2 
    currentWidth += 32 
end 

我是新来ruby编程和chunkypng,所以任何帮助,非常感谢。

谢谢。

试试这个:

newpic = newpic.replace(strips[0], offset_x = 0, offset_y = 0) 
newpic.save('name.png') # save when done 

随着替代方法,你可以从你的阵列选择任意条,并根据偏移量奠定下来在画布上。这是你想到的吗?

+0

谢谢,工作完美 – initWithStyle