English 中文(简体)
TGifImage Transparency Issue
原标题:TGifImage Transparency Issue

I am using TGifImage that is included with Delphi XE.

我试图做的是把吉夫从档案中排出来,把所有框架推到比图。

这是我迄今为止所做的事情:

procedure ExtractGifFrames(FileName: string);
var
  Gif: TGifImage;
  Bmp: TBitmap;
  i: Integer;
begin
  Gif := TGifImage.Create;
  try
    Gif.LoadFromFile(FileName);

    Bmp := TBitmap.Create;
    try
      Bmp.SetSize(Gif.Width, Gif.Height);

      for i := 0 to Gif.Images.Count - 1 do
      begin
        if not Gif.Images[i].Empty then
        begin
          Bmp.Assign(Gif.Images[i]);
          Bmp.SaveToFile( C:	estitmap  + IntToStr(i) +  .bmp );
        end;
      end;
    finally
      Bmp.Free;
    end;
  finally
    Gif.Free;
  end;
end;

procedure TForm1.Button1Click(Sender: TObject);
begin
  if OpenPictureDialog1.Execute then
  begin
    ExtractGifFrames(OpenPictureDialog1.FileName);
  end;
end;

我面临的问题是一些透明度问题,涉及许多不同的吉夫,也涉及规模问题。

下面是利用我上述法典节省下来的一些实例:

enter image description here enter image description here

由于你看不到成果,结果就存在规模和透明度问题。

我知道Gif文档本身不是腐败的,因为我可以通过我的网络浏览器装载这些档案,而且这些记录显示正确无误。

我怎么能够把盖夫从档案中排出来,在不失去任何质量的情况下将每个框架分配给比图?

最佳回答

www.un.org/spanish/ecosoc 关于较老的德尔菲版本(2009年之前): 研究<代码> GIFImage unit, You may be we toeck how TGIFPainter makes texts based on each Frame scode>Disposal.

我已用<条码> TGIFPainter.OnAfterPaint,为挽救BMP的积极框架而撰写了一部小型法律,并做了所有的“艰苦工作”。

注:GIFImage unit edition 2.2 Release: 5 (23-MAY-1999)

type
  TForm1 = class(TForm)
    Button1: TButton;
    ProgressBar1: TProgressBar;
    procedure Button1Click(Sender: TObject);
  public
    FBitmap: TBitmap;
    procedure AfterPaintGIF(Sender: TObject);
  end;

...

procedure TForm1.Button1Click(Sender: TObject);
var
  GIF: TGIFImage;
begin
  GIF := TGIFImage.Create;
  FBitmap := TBitmap.Create;
  Button1.Enabled := False;
  try
    GIF.LoadFromFile( c:	est	est.gif );
    GIF.DrawOptions := GIF.DrawOptions - [goLoop, goLoopContinously, goAsync];
    GIF.AnimationSpeed := 1000; // Max - no delay
    FBitmap.Width := GIF.Width;
    FBitmap.Height := GIF.Height;
    GIF.OnAfterPaint := AfterPaintGIF;

    ProgressBar1.Max := Gif.Images.Count;
    ProgressBar1.Position := 0;
    ProgressBar1.Smooth := True;
    ProgressBar1.Step := 1;

    // Paint the GIF onto FBitmap, Let TGIFPainter do the painting logic
    // AfterPaintGIF will fire for each Frame
    GIF.Paint(FBitmap.Canvas, FBitmap.Canvas.ClipRect, GIF.DrawOptions);
    ShowMessage( Done! );
  finally
    FBitmap.Free;
    GIF.Free;
    Button1.Enabled := True;
  end;
end;

procedure TForm1.AfterPaintGIF(Sender: TObject);
begin
  if not (Sender is TGIFPainter) then Exit;
  if not Assigned(FBitmap) then Exit;
  // The event will ignore Empty frames      
  FBitmap.Canvas.Lock;
  try
    FBitmap.SaveToFile(Format( %.2d.bmp , [TGIFPainter(Sender).ActiveImage]));
  finally
    FBitmap.Canvas.Unlock;
  end;
  ProgressBar1.StepIt;
end;

注:没有处理错误以简化守则。

“output


www.un.org/spanish/ecosoc 新德尔菲版(2009年+): 有了建立-inGIFImg的单位,你就能够使用TGIFPainter) e.g:

procedure TForm1.Button1Click(Sender: TObject);
var
  GIF: TGIFImage;
  Bitmap: TBitmap;
  I: Integer;
  GR: TGIFRenderer;
begin
  GIF := TGIFImage.Create;      
  Bitmap := TBitmap.Create;
  try
    GIF.LoadFromFile( c:	est	est.gif );
    Bitmap.SetSize(GIF.Width, GIF.Height);
    GR := TGIFRenderer.Create(GIF);
    try
      for I := 0 to GIF.Images.Count - 1 do
      begin
        if GIF.Images[I].Empty then Break;
        GR.Draw(Bitmap.Canvas, Bitmap.Canvas.ClipRect);
        GR.NextFrame;
        Bitmap.SaveToFile(Format( %.2d.bmp , [I]));
      end;
    finally
      GR.Free;
    end;  
  finally
    GIF.Free;
    Bitmap.Free;
  end;
end;

www.un.org/spanish/ecosoc 利用全球发展指数+:

uses ..., GDIPAPI, GDIPOBJ, GDIPUTIL;

procedure ExtractGifFrames(const FileName: string);
var
  GPImage: TGPImage;
  encoderClsid: TGUID;
  BmpFrame: TBitmap;
  MemStream: TMemoryStream;
  FrameCount, FrameIndex: Integer;
begin
  GPImage := TGPImage.Create(FileName);
  try
    if GPImage.GetLastStatus = Ok then
    begin
      GetEncoderClsid( image/bmp , encoderClsid);
      FrameCount := GPImage.GetFrameCount(GDIPAPI.FrameDimensionTime);
      for FrameIndex := 0 to FrameCount - 1 do
      begin
        GPImage.SelectActiveFrame(GDIPAPI.FrameDimensionTime, FrameIndex);
        MemStream := TMemoryStream.Create;
        try
          if GPImage.Save(TStreamAdapter.Create(MemStream), encoderClsid) = Ok then
          begin
            MemStream.Position := 0;
            BmpFrame := TBitmap.Create;
            try
              BmpFrame.LoadFromStream(MemStream);
              BmpFrame.SaveToFile(Format( %.2d.bmp , [FrameIndex]));
            finally
              BmpFrame.Free;
            end;
          end;
        finally
          MemStream.Free;
        end;
      end;
    end;
  finally
    GPImage.Free;
  end;
end;
问题回答

缩略语表文档框架往往只包含与先前框架的不同之处(一种减少档案规模的优化技术)。 因此,为了在某个特定时刻对全球投资安排进行简要描述,你不得不把所有框架搁置到那个时候,一个是在那个时候。

我们可以通过使用<代码>Draw(<>>>>>>>)及其透明选择套来实现:

procedure ExtractGifFrames(FileName: string);
var
  Gif: TGifImage;
  Bmp: TBitmap;
  i: Integer;
  Bounds: TRect;
begin
  Gif := TGifImage.Create;
  try
    Gif.LoadFromFile(FileName);
    Bounds := Rect(0, 0, Gif.Width-1, Gif.Height-1);

    Bmp := TBitmap.Create;
    try
      Bmp.SetSize(Gif.Width, Gif.Height);
      Bmp.PixelFormat := pf32bit;

      for i := 0 to Gif.Images.Count - 1 do
      begin
        if not Gif.Images[i].Empty then
        begin
          Gif.Images[i].Draw(Bmp.Canvas, Bounds, True, True);
          Bmp.SaveToFile(IntToStr(i) +  .bmp );
        end;
      end;
    finally
      Bmp.Free;
    end;
  finally
    Gif.Free;
  end;
end;

NB:在计算全球投资框架格式时还有其他内容,其中具体规定了时间范围,但可能并不涉及你。





相关问题
determining the character set to use

my delphi 2009 app has a basic translation system that uses GNUGetText. i had used some win API calls to prepare the fonts. i thought it was working correctly until recently when someone from Malta ...

Help with strange Delphi 5 IDE problems

Ok, I m going nuts here. For the last (almost) four years, I ve been putting up with some extremely bad behavior from my Delphi 5 IDE. Problems include: Seemingly random errors in coride50.bpl ...

How to write a Remote DataModule to run on a linux server?

i would like to know if there are any solution to do this. Does anyone? The big picture: I want to access data over the web, using my delphi thin clients. But i´would like to keep my server/service ...

How convert string to integer in Oxygene

In Delphi, there is a function StrToInt() that converts a string to an integer value; there is also IntToStr(), which does the reverse. These functions doesn t appear to be part of Oxygene, and I can ...

Quick padding of a string in Delphi

I was trying to speed up a certain routine in an application, and my profiler, AQTime, identified one method in particular as a bottleneck. The method has been with us for years, and is part of a "...

热门标签