Components for Delphi and C++ Builder.

Go to Russian forum
Go to EhLib.com
It is currently 27 Apr 2024, 09:44

All times are UTC




Post new topic Reply to topic  [ 4 posts ] 
Author Message
 Post subject: Gif Animate on column
PostPosted: 05 Mar 2024, 15:11 
Offline

Joined: 31 Aug 2018, 19:06
Posts: 92
Hi,
Can I show gif animate on column by OnAdvDrawDataCell event?


Top
 Profile  
 
PostPosted: 16 Mar 2024, 09:48 
Offline

Joined: 31 Aug 2018, 19:06
Posts: 92
Is there a way?


Top
 Profile  
 
PostPosted: 16 Mar 2024, 23:13 
Offline

Joined: 08 May 2014, 18:06
Posts: 663
Hello

Unfortunately, there is no easy way to display animated images in the grid.
But this possibility can be realized if you divide the image into separate frames and draw each frame into grid cells according to a timer.
I am attaching an example of how this feature can be implemented.


Code:
  TForm1 = class(TForm)
...
  private
  public
    Bitmaps: TList<TBitmap>;
    FrameIndex: Integer;
  end;


//divide the image into separate frames
Code:
procedure TForm1.Button1Click(Sender: TObject);
var
  GIFImage: TGIFImage;
//  BackgroundColor: TColor;
  I: Integer;
begin
  GIFImage := Image1.Picture.Graphic as TGIFImage;
  GIFImage.Animate := True;
//  BackgroundColor := GIFImage.BackgroundColor;

  for I := 0 to GIFImage.Images.Count - 1 do
  begin
    Bitmaps.Add(GIFImage.Images[I].Bitmap);
  end;

  Timer1.Interval := GIFImage.AnimationSpeed;
  Timer1.Enabled := True;
  DBGridEh1.Invalidate;
end;


//Draw Grid Cell Data

Code:
procedure TForm1.DBGridEh1Columns0AdvDrawDataCell(Sender: TCustomDBGridEh; Cell,
  AreaCell: TGridCoord; Column: TColumnEh; const ARect: TRect;
  var Params: TColCellParamsEh; var Processed: Boolean);
var
  DestRect: TRect;
  Bitmap: TBitmap;
begin
  Sender.DrawColumnDataCellBackground(Cell, AreaCell, Column, ARect, Params);
  if MemTableEh1.FieldByName('Name').AsString = 'Bolivia' then
  begin
    if Bitmaps.Count > 0 then
    begin
      Bitmap := Bitmaps[FrameIndex];
      DestRect := GetDestRectForImagePlacement(CreateSize(Bitmap.Width, Bitmap.Height), ARect, TImagePlacementEh.ipFitEh);
      Sender.Canvas.StretchDraw(DestRect, Bitmap);
    end;
  end;
  Processed := True;
end;


//Change FrameIndex in the Times
Code:
procedure TForm1.Timer1Timer(Sender: TObject);
begin
  Inc(FrameIndex);
  if FrameIndex >= Bitmaps.Count then
    FrameIndex := 0;
  TDBGridEhCrack(DBGridEh1).InvalidateCol(1);
end;


Attachments:
2024-03-16-AnimatedGifsInGrid.zip [16.41 KiB]
Downloaded 15 times

_________________
Best regards
EhLib Support Team
Top
 Profile  
 
PostPosted: 17 Mar 2024, 07:13 
Offline

Joined: 31 Aug 2018, 19:06
Posts: 92
thanks


Top
 Profile  
 
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 4 posts ] 

All times are UTC


Who is online

Users browsing this forum: No registered users and 55 guests


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Jump to:  
cron
Powered by phpBB® Forum Software © phpBB Group