teroni
2008-09-12 08:20:12 UTC
I am attempting to create an animated GIF
from a list of bitmaps. The file gets created
and saved to the hard drive just fine, but
the output does not open in windows XP
picture viewer (it says "Drawing failed").
Fire fox, internet explorer, and other
picture viewers can read it just fine, but
the animation speed gets ignored. What
am I doing wrong with the following code?
TGifImage is version 2.2 and using BCB4.
The delphi demos are not helping and
do not contain cpp examples.
#include <vcl.h>
void SaveAsGifAnim()
{
int i, percent, width, height, totalRendered, totalImages;
int borderSizeWidthPercent, borderSizeHeightPercent;
int repeatValueInt, repeatCount, repeatTotal, pixelFormat;
double repeatValue, repeatRemainder;
double currentImage, framesPerSecond, periodBetweenFrames;
bool ShowCompressionOptions;
bool maintainAspectChecked = true, zoomInChkBoxChecked = true;
TRect rect;
Graphics::TBitmap *bitmap = new Graphics::TBitmap();
TGIFImage *gifAnim = new TGIFImage;
try
{
totalImages = StringGrid->RowCount * RepeatValueEdit-
height = HeightEdit->Value;
rect.Top = 0;
rect.Left = 0;
rect.Right = width;
rect.Bottom = height;
gifAnim->ColorReduction = rmQuantize;
borderSizeWidthPercent = BorderSizeWidthEdit->Value;
borderSizeHeightPercent = BorderSizeHeightEdit->Value;
maintainAspectChecked = AspectChkBox->Checked;
zoomInChkBoxChecked = ZoomInChkBox->Checked;
repeatValue = RepeatValueEdit->Text.ToDouble();
repeatValueInt = repeatValue;//chop off decimal.
repeatRemainder = 0;
currentImage = 1;
pixelFormat = PixelFormCBox->Tag;
for (i = 0; i < StringGrid->RowCount; i++)
{
LoadImage(BuffImage, StringGrid->Cells[ImageCol][i]);
//apply effects BuffImage
ApplyListOfEffects(BuffImage, StringGrid->Cells[EffectCol][i]);
//Adjust image to GIF dimensions.
GetAspectedImage(BuffImage, AVIBackImage, width, height,
borderSizeWidthPercent,
borderSizeHeightPercent,
pixelFormat, maintainAspectChecked,
zoomInChkBoxChecked);
bitmap->PixelFormat = (TPixelFormat) pixelFormat;
bitmap->Width = BuffImage->Picture->Bitmap->Width;
bitmap->Height = BuffImage->Picture->Bitmap->Height;
bitmap->Canvas->Draw(0,0, BuffImage->Picture->Bitmap);
//Done Adjusting image to GIF Dimensions.
//Add repeated frames.
repeatRemainder += repeatValue - repeatValueInt;
repeatTotal = repeatValueInt;
repeatTotal += repeatRemainder;
if (repeatRemainder >= 1)
repeatRemainder -= 1;
for(repeatCount = 0; repeatCount < repeatTotal; repeatCount++)
{
int result;
result = gifAnim->Add(bitmap);
if (result == 0)
{
TGIFAppExtNSLoop *loopExt;
loopExt = new TGIFAppExtNSLoop(gifAnim->
Images->SubImages[result]);
loopExt->Loops = 0;//supposed to make it loop infinitely,
but does not.
gifAnim->Images->SubImages[result]->Extensions-
}
TGIFGraphicControlExtension * ext;
ext = new TGIFGraphicControlExtension(gifAnim->
Images->SubImages[result]);
ext->Delay = 1000;//delay does not work either
gifAnim->Images->SubImages[result]->Extensions->Add(ext);
delete ext;
gifAnim->OptimizeColorMap();
currentImage++;
}
//Done adding repeated frames.
}//end for loop i.
//now save GIF to file
gifAnim->SaveToFile(OutputEdit->Text);
}
catch (Exception &exception)
{
Application->ShowException(&exception);
}
delete bitmap;
delete gifAnim;
}
--
Anthony West
from a list of bitmaps. The file gets created
and saved to the hard drive just fine, but
the output does not open in windows XP
picture viewer (it says "Drawing failed").
Fire fox, internet explorer, and other
picture viewers can read it just fine, but
the animation speed gets ignored. What
am I doing wrong with the following code?
TGifImage is version 2.2 and using BCB4.
The delphi demos are not helping and
do not contain cpp examples.
#include <vcl.h>
void SaveAsGifAnim()
{
int i, percent, width, height, totalRendered, totalImages;
int borderSizeWidthPercent, borderSizeHeightPercent;
int repeatValueInt, repeatCount, repeatTotal, pixelFormat;
double repeatValue, repeatRemainder;
double currentImage, framesPerSecond, periodBetweenFrames;
bool ShowCompressionOptions;
bool maintainAspectChecked = true, zoomInChkBoxChecked = true;
TRect rect;
Graphics::TBitmap *bitmap = new Graphics::TBitmap();
TGIFImage *gifAnim = new TGIFImage;
try
{
totalImages = StringGrid->RowCount * RepeatValueEdit-
Text.ToDouble();
width = WidthEdit->Value;height = HeightEdit->Value;
rect.Top = 0;
rect.Left = 0;
rect.Right = width;
rect.Bottom = height;
gifAnim->ColorReduction = rmQuantize;
borderSizeWidthPercent = BorderSizeWidthEdit->Value;
borderSizeHeightPercent = BorderSizeHeightEdit->Value;
maintainAspectChecked = AspectChkBox->Checked;
zoomInChkBoxChecked = ZoomInChkBox->Checked;
repeatValue = RepeatValueEdit->Text.ToDouble();
repeatValueInt = repeatValue;//chop off decimal.
repeatRemainder = 0;
currentImage = 1;
pixelFormat = PixelFormCBox->Tag;
for (i = 0; i < StringGrid->RowCount; i++)
{
LoadImage(BuffImage, StringGrid->Cells[ImageCol][i]);
//apply effects BuffImage
ApplyListOfEffects(BuffImage, StringGrid->Cells[EffectCol][i]);
//Adjust image to GIF dimensions.
GetAspectedImage(BuffImage, AVIBackImage, width, height,
borderSizeWidthPercent,
borderSizeHeightPercent,
pixelFormat, maintainAspectChecked,
zoomInChkBoxChecked);
bitmap->PixelFormat = (TPixelFormat) pixelFormat;
bitmap->Width = BuffImage->Picture->Bitmap->Width;
bitmap->Height = BuffImage->Picture->Bitmap->Height;
bitmap->Canvas->Draw(0,0, BuffImage->Picture->Bitmap);
//Done Adjusting image to GIF Dimensions.
//Add repeated frames.
repeatRemainder += repeatValue - repeatValueInt;
repeatTotal = repeatValueInt;
repeatTotal += repeatRemainder;
if (repeatRemainder >= 1)
repeatRemainder -= 1;
for(repeatCount = 0; repeatCount < repeatTotal; repeatCount++)
{
int result;
result = gifAnim->Add(bitmap);
if (result == 0)
{
TGIFAppExtNSLoop *loopExt;
loopExt = new TGIFAppExtNSLoop(gifAnim->
Images->SubImages[result]);
loopExt->Loops = 0;//supposed to make it loop infinitely,
but does not.
gifAnim->Images->SubImages[result]->Extensions-
Add(loopExt);
delete loopExt;}
TGIFGraphicControlExtension * ext;
ext = new TGIFGraphicControlExtension(gifAnim->
Images->SubImages[result]);
ext->Delay = 1000;//delay does not work either
gifAnim->Images->SubImages[result]->Extensions->Add(ext);
delete ext;
gifAnim->OptimizeColorMap();
currentImage++;
}
//Done adding repeated frames.
}//end for loop i.
//now save GIF to file
gifAnim->SaveToFile(OutputEdit->Text);
}
catch (Exception &exception)
{
Application->ShowException(&exception);
}
delete bitmap;
delete gifAnim;
}
--
Anthony West