【问题标题】:ImageMagick. What is the correct way to dice an image into sub-tiles图像魔术。将图像切成小块的正确方法是什么
【发布时间】:2013-12-06 21:25:36
【问题描述】:

将图像切成 N x N 子图块图像的正确方法是什么?

谢谢,
道格

【问题讨论】:

    标签: imagemagick


    【解决方案1】:

    谢谢,

    实际上,我做了一点尝试,想出了正确的 imagemagick 咒语。

    这是 tcsh 版本。

    将图像切成 4 x 4 的网格(生成的图像按顺序编号)。数制解释为:col + row * nrows:

    $ convert -crop 25%x25% image.png tile-prefix.png
    

    通常需要将顺序编号重新映射到行 x 列。例如,如果您在 iOS 应用程序中使用 CATiledLayer,并且需要为给定比例摄取正确的切片。方法如下:

    while ( $i < $number_of_tiles )  
    while -> set r = `expr $i \/ 4`  
    while -> set c = `expr $i \% 4`  
    while -> cp tile-prefix-$i.png tile-prefix-${r}x${c}.png  
    while -> echo $i  
    while -> @ i++  
    while -> end
    

    【讨论】:

    • 您可以使用 FX Escapes 让 IM 相应地命名图块,例如 -set filename:tile "%[fx:page.x/4+1]_%[fx:page.y/4+1]"
    • 对于数字系统,您的意思是row * ncols + col
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2011-12-16
    • 2011-07-06
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多