Anonymous user
Bitmap/Write a PPM file: Difference between revisions
m
Fixed lang tags.
m (→{{header|Python}}: Remove the old func.) |
m (Fixed lang tags.) |
||
Line 6:
=={{header|Ada}}==
<lang ada>with Ada.Characters.Latin_1;
with Ada.Streams.Stream_IO; use Ada.Streams.Stream_IO;
Line 32 ⟶ 31:
end loop;
Character'Write (Stream (File), LF);
end Put_PPM;</lang>
</lang>▼
The solution writes the image into an opened file. The file format might fail to work on certain [[OS]]es, because output might mangle control characters like LF, CR, FF, HT, VT etc. The OS might also limit the line length of a text file. In general it is a bad idea to mix binary and text output in one file. This solution uses ''stream I/O'', which should be as portable as possible.
=={{header|AutoHotkey}}==
<lang AutoHotkey>imwrite_ppm(filename, width, height, colors)
{
ppmfile =
Line 48 ⟶ 45:
}
imwrite_ppm("blank.ppm", 256, 256, 255)</lang>
</lang>▼
=={{header|C}}==
Line 72 ⟶ 68:
=={{header|C sharp|C#}}==
This implementation uses a StreamWriter to write the header in text, then writes the pixel data in binary using a BinaryWriter.
<lang csharp>using System;
using System.IO;
class PPMWriter
Line 96 ⟶ 91:
writerB.Close();
}
▲}</lang>
=={{header|Common Lisp}}==
Line 128 ⟶ 122:
(write-byte green stream)
(write-byte blue stream)))))))
filename)</lang>
=={{header|D}}==
Line 138 ⟶ 131:
Two additional imports are needed:
import tango.io.protocol.
▲import tango.io.protocol.model.IWriter;
P6Image will implement IWritable interface
<lang D>class P6Image : IWritable {
//....
Line 178 ⟶ 168:
output (); // flush
}
▲}</lang>
Saving a file is easy as a pie:
<lang D>auto p6 = new P6Image(new FileConduit("image.ppm"));▼
▲auto p6 = new P6Image(new FileConduit("image.ppm"));
auto write = new Writer(new FileConduit("out.ppm", FileConduit.WriteCreate));
write (p6);</lang>
=={{header|E}}==
Line 194 ⟶ 181:
=={{header|Forth}}==
=={{header|Fortran}}==
Line 299 ⟶ 286:
=={{header|J}}==
'''Solution:'''
<lang j>require 'files'
NB. ($x) is height, width, colors per pixel
Line 309 ⟶ 295:
'''Example:'''
Using routines from [[Basic_bitmap_storage#J|Basic Bitmap Storage]]:
<lang j> NB. create 10 by 10 block of magenta pixels in top right quadrant of a 300 wide by 600 high green image▼
▲ NB. create 10 by 10 block of magenta pixels in top right quadrant of a 300 wide by 600 high green image
myimg=: ((145 + pixellist) ; 255 0 255) setPixels 0 255 0 makeRGB 600 200
myimg writeppm jpath '~temp/myimg.ppm'
360015</lang>
=={{header|Modula-3}}==
|