1 {unit to write tbitmaps to a png using plugwashes png code}
\r
3 unit pngwritetbitmap;
\r
21 procedure savetbitmaptopng(image:tbitmap;destination : tstream);
\r
23 procedure savetbitmaptopng(image:tbitmap;destination : tstream);
\r
25 paletteentrieswin : array[0..255] of TPaletteEntry;
\r
26 paletteentriespng : array[0..768] of byte;
\r
29 colortype : tcolortype;
\r
31 if (image.PixelFormat <> pf8bit) and (image.pixelformat <> pf24bit) then raise exception.create('unsupported image format, only 8 bit and 24 bit per pixel are currently supported.');
\r
32 if image.PixelFormat = pf24bit then begin
\r
35 colortype := ctpallette;
\r
37 pngstart(f,destination,8,colortype,image.Height,image.Width);
\r
39 if image.pixelformat = pf8bit then begin
\r
40 GetPaletteEntries(image.Palette,0,256,paletteEntrieswin);
\r
42 //writeln('about to start png write');
\r
43 //writeln('about to prepare pallette');
\r
44 for i := 0 to 255 do begin
\r
45 paletteentriespng[(i*3) ] := paletteEntrieswin[i].pered;
\r
46 paletteentriespng[(i*3)+1] := paletteEntrieswin[i].pegreen;
\r
47 paletteentriespng[(i*3)+2] := paletteEntrieswin[i].peblue;
\r
49 //writeln('about to write pallette');
\r
50 pngwritepal(f,@paletteentriespng,256 );
\r
55 for i := 0 to Image.Height -1 do begin;
\r
56 //writeln('about to write scanline ',i,'image.height=',image.height,'image.ScanLine[i]',longint(image.ScanLine[i]));
\r
57 pngwritescanline(f,image.ScanLine[i]);
\r
59 //writeln('about to close main data block');
\r
61 //writeln('about to close png');
\r