Entwickler-Ecke

Delphi Language (Object-Pascal) / CLX - save bitmap as pnm, pgm, pbm, ppm or pcx?


chukalv - Mi 12.07.06 18:59
Titel: save bitmap as pnm, pgm, pbm, ppm or pcx?
Are there any techniques to save simple Timage bitmap as any of these image extensions "pgm, pbm, ppm"? These are the Portable PixMap/GreyMap/BitMap files.
Here`s [http://astronomy.swin.edu.au/~pbourke/dataformats/ppm/] an description about the image file structure. As I`m very bad at logical thinking, could someone explain how to save these images as I understood they are given out as plain text/ASCII...

The image is black and white.

P.S. The "ImageFileLib" component doesn`t work as should, it gives out a scratched image.


chukalv - Mi 12.07.06 19:23

Almost forgot. Here`s what I`ve done. But it doesn`t work...


Delphi-Quelltext
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
16:
var
i,x : integer;
begin
memo1.Lines.Add('P3');
memo1.lines.Add(inttostr(image1.width));
memo1.lines.Add(inttostr(image1.height));
memo1.lines.Add('2');

for i := 4 to image1.height do
begin
memo1.lines.Add('');
for x := 0 to image1.width
do if image1.Canvas.Pixels[x,i] = clblack then memo1.lines[i] := memo1.lines[i]+ ' 1' else memo1.lines[i] := memo1.lines[i]+ ' 0';
memo1.lines[i] := copy(memo1.lines[i],2,length(memo1.lines[i]));
end;
memo1.lines.SaveToFile('C:\example.pgm');