LoginSignup
0
0

More than 5 years have passed since last update.

Julialangで外部ライブラリを使わずにppmファイルを書き出す

Posted at

Char型だとダメで、Cuchar型の配列だと、writeで配列を指定するだけでOK。

function saveppm(fname,  w,  h, img)
    open(fname, "w") do fp
      write(fp, "P6\n");
      write(fp, "$w $h\n");
      write(fp, "255\n");
      write(fp, img)
    end
end

img = Array(Cuchar,WIDTH * HEIGHT * 3)
for i = 1:length(img)
    img[i]=Cuchar(round(Int,rand()*255))
end

saveppm("image.ppm", WIDTH, HEIGHT, img)
0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0