PNG to PCL in Delphi 2005

The MagickWand interface is a new high-level C API interface to ImageMagick core methods. We discourage the use of the core methods and encourage the use of this API instead. Post MagickWand questions, bug reports, and suggestions to this forum.
Post Reply
hdesai24
Posts: 2
Joined: 2012-01-19T14:57:42-07:00
Authentication code: 8675308

PNG to PCL in Delphi 2005

Post by hdesai24 »

I am trying to convert PNG to PCL using ImageMagick and it works wonderfully.

There are constraints to copying all ImageMagick dll files, what i am looking out for is just one single dll which exports the "convert" method without having to register itself. This dll should require bare minimum dependent files. Can't go with COM+ objects, is there any non ActiveX dll which i can use in my Delphi 2005 application.

Just want to call loadlibrary and call the method to convert. Any help is appreciated.
hdesai24
Posts: 2
Joined: 2012-01-19T14:57:42-07:00
Authentication code: 8675308

Re: PNG to PCL in Delphi 2005

Post by hdesai24 »

Found the solution,

I didn't use ImageMagick since i couldn't go for COM objects, instead this is a all delphi solution.

I had a True Colour PNG Barcode Image which had to be converted to PCL, did the conversion using TPngImage (http://stackoverflow.com/questions/8898 ... equivalent) and GIFImage.pas (http://www.tolderlund.eu/delphi/)

uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, StdCtrls, pngimage, GIFImage;

var
PNGImg: TPNGObject;
BMPImg, BWImg: TBitmap;
Output: System.Text;

Begin
PNGImg := TPNGObject.Create;
BMPImg := TBitmap.Create;

PNGImg.LoadFromFile('Image.png');
PNGImg.AssignTo(BMPImg);
// Call GifImage Reduce Colours to reduce from RGB to MonoChrome (Black and white)
BWImg := ReduceColors(BMPImg, rmMonochrome, dmNearest, 1, 0);
// Reduce to 1 bit Depth
BWImg.PixelFormat := pf1bit;

AssignFile(output, Output.pcl');
Rewrite(output);
EncodeGraphicAsPCL(BWImg, pclstr);
Write(output, pclstr);
CloseFile(output);
end;

// This one is straight out of http://www.delphigroups.info/2/11/322198.html

Procedure EncodeGraphicAsPCL(aGraphic: TBitmap; var AOutString: string);
const
cGraphicsBegin = #27+'*r0F' + #27+'*t0300R' + #27+'*r1A';
cGraphicsChunk = #27+'*b%dW%s'; // the number of bytes in the chunk must replace "%d"
cGraphicsEnd = #27+'*rB';
var
vNdx: integer;
vtmpLine: string;
vRow: pByteArray;
vBytesInGraphicRow: integer;
i: integer;
x: byte;
begin
AOutString := '';
// Div by 8
vBytesInGraphicRow := (aGraphic.Width div Eight );
// Mod by 8
if (aGraphic.Width mod Eight)>0 then
inc(vBytesInGraphicRow);
for vNdx := 0 to aGraphic.Height - 1 do
begin
vRow := pByteArray(aGraphic.ScanLine[vNdx]);
vtmpLine := '';
for i := 1 to vBytesInGraphicRow do
begin
x := vRow[i-1];
x := NOT x;
vtmpLine := vtmpLine + char(x);
end;
AOutString := AOutString + format(cGraphicsChunk, [vBytesInGraphicRow,
vtmpLine]);
end;
if length(AOutString)>0 then
begin
AOutString := cGraphicsBegin + AOutString + cGraphicsEnd;
end;
end;

End;
Post Reply