procedure TfrmMain.actGeneratorPagedImageExecute(Sender: TObject);
var
frm : TfrmDLGPagedImageGenerator;
lst : TStringList;
a : Integer;
TIF : TBGRAWriterTiff;
img : TFPMemoryImage;
Bgra, bgraSized : TBgraBitmap;
strm : TFileStream;
strOutput : string;
Gif : TBGRAAnimatedGif;
Size : TPoint;
// opt : TBGRAColorQuantizerAny;
// ADitheringAlgorithm : TDitheringAlgorithm
begin
frm := TfrmDLGPagedImageGenerator.create(self);
try
lst := TStringList.create;
try
GetCurrentList(lst);
for A := 0 to lst.count - 1 do
begin
frm.AddToFiles(lst[a]);
end;
finally
lst.free;
end;
if frm.ShowModal = mrOK then
begin
strOutput := frm.feOutput.filename;
if frm.cboType.ItemIndex = 0 then ChangeFileExt(strOutput, '.tif')
else if frm.cboType.ItemIndex = 1 then changeFileExt(strOutput, '.gif');
if frm.cboType.ItemIndex = 0 then
begin
// TIFF Image
TIF := TBgraWriterTiff.Create;
try
tif.PremultiplyRGB := true;
tif.SaveCMYKAsRGB := true;
pbar.MaxValue := frm.lvFiles.items.count - 1;
for A := 0 to frm.lvFiles.items.count - 1 do
begin
pbar.value := a;
application.ProcessMessages;
Bgra := TBgraBitmap.create;
try
LoadToBgra(frm.lvFiles.items.item[a].Caption, bgra);
Bgra.ClearTransparentPixels;
img := TFPMemoryImage.Create(bgra.width, bgra.height);
try
img.assign(bgra);
Tif.AddImage(img);
finally
img.free;
end;
finally
bgra.free;
end;
end;
if fileExists(strOutput) then RecycleItem(strOutput, true, false, true);
strm := TFilestream.create(strOutput, fmCreate);
try
tif.SaveToStream(strm);
finally
strm.free;
end;
application.ProcessMessages;
if fileExists(strOutput) then
begin
DoMessage('Paged Image Generator', ExtractFileName(strOutput) + ' - Generated!');
if ask('Would you like to open the file?') = mrYes then LoadAnyFile(strOutput);
end else DoWarning('Paged Image Generator', ExtractFileName(strOutput) + ' - Not Generated!');
finally
TIF.free;
end;
end else if frm.cboType.ItemIndex = 1 then
begin
// Write to GIF
Gif := TBGRAAnimatedGif.Create;
try
if frm.lvFiles.items.count-1=-1 then
begin
DoWarning('Paged Image Generator', 'Cannot add zero images!');
exit;
end;
Bgra := TBgraBitmap.create;
try
LoadToBgra(frm.lvFiles.items.item[0].caption, bgra);
size.x := Bgra.Width;
size.y := bgra.height;
finally
bgra.free;
end;
gif.SetSize(size.x, size.y);
gif.LoopCount := frm.lvFiles.items.count-1;
pbar.MaxValue := frm.lvFiles.items.count - 1;
for a := 0 to frm.lvFiles.items.count - 1 do
begin
pbar.value := a;
application.ProcessMessages;
Bgra := TBgraBitmap.create;
try
LoadToBgra(frm.lvFiles.items.item[a].caption, bgra);
application.ProcessMessages;
Bgra.ResampleFilter := rfBestQuality;
bgraSized := TbgraBitmap.create(size.x, size.y);
try
BgraSized.ResampleFilter := rfBestQuality;
BgraSized := Bgra.Resample(size.x, size.y, rmFineResample);
GIF.AddFullFrame(BgraSized, 50);
finally
BgraSized.free;
end;
finally
bgra.free;
end;
end;
ShowMessage(strOutput);
if fileExists(strOutput) then RecycleItem(strOutput, true, false, true);
strm := TFileStream.create(strOutput, fmCreate);
try
try
Gif.SaveToStream(strm, BGRAColorQuantizerFactory, daFloydSteinberg);
except
//
end;
finally
strm.free;
end;
application.ProcessMessages;
if fileExists(strOutput) then
begin
DoMessage('Paged Image Generator', ExtractFileName(strOutput) + ' - Generated!');
if ask('Would you like to open the file?') = mrYes then LoadAnyFile(strOutput);
end else DoWarning('Paged Image Generator', ExtractFileName(strOutput) + ' - Not Generated!');
finally
gif.free;
end;
end;
end;
finally
frm.free;
end;
end;