Linux在命令行中逐个像素地创建Image

Linux中有没有办法直接在命令行中创建图像并逐个像素地构建它?

我尝试了imagemagick,但它只能创建一个没有设置像素单独的空白图像.

任何的想法?

解决方法:

您可以使用shell脚本来构建ppm映像.

echo "P2"
echo "# Column (width) Row (height)"
echo "$1 $1\n1"

t=`expr $1 / 8`
for i in `seq 1 4`; do
    for i in `seq 1 $t`; do
        for i in `seq 1 4`; do
            for i in `seq 1 $t`; do echo -n "1 "; done
            for i in `seq 1 $t`; do echo -n "0 "; done
        done
        echo
    done
    for i in `seq 1 $t`; do
        for i in `seq 1 4`; do
            for i in `seq 1 $t`; do echo -n "0 "; done
            for i in `seq 1 $t`; do echo -n "1 "; done
        done
        echo
    done
done

要运行上面的代码,请执行:

$sh filename.sh 120 > im1.ppm ; eog im1.ppm

结果是:
enter image description here

上一篇:Android面试一天一题(1Day)


下一篇:python+opencv图像处理:图片加载保存