Recent

Author Topic: DBGRID not responsive when I load pics from db into column cells  (Read 2535 times)

hamacker

  • New Member
  • *
  • Posts: 18
DBGRID not responsive when I load pics from db into column cells
« on: November 25, 2021, 05:02:45 pm »
Hi guys,
I have a DBGrid that show me a table with blob images where only '.jpg' and '.bmp' in 1024x1024px are acceptable.
The images are faces pictures stretched to 64x64 in dbgrid cell, my problem is that my code bellow is fast to show in dbgrid, but not responsive to navigate when I click or move up/down, need to wait each move.
The code is:
Code: Pascal  [Select][+][-]
  1. var
  2.   db_tmpfoto:TDBImage;
  3.   fixRect : TRect;
  4.   bmpWidth : integer;
  5. begin
  6.   if Sender is TDBGrid then
  7.   begin
  8.     fixRect := Rect;
  9.     with TDBGrid(Sender) do
  10.     begin
  11.       (...)
  12.       fixRect := Rect;
  13.       if Column.Index=0 then  // pic in column index 0
  14.       begin
  15.         Canvas.FillRect(Rect);
  16.         db_tmpfoto:=TDBImage.Create(nil);
  17.         try
  18.           db_tmpfoto.Datasource:=DS_Qry_Pesqusia;
  19.           db_tmpfoto.DataField:='foto';
  20.           bmpWidth := (Rect.Bottom - Rect.Top);
  21.           fixRect.Right := Rect.Left + bmpWidth;
  22.           Canvas.StretchDraw(fixRect,db_tmpfoto.Picture.Bitmap);
  23.         finally
  24.           db_tmpfoto.free;
  25.         end;
  26.       end;
  27.     end;
  28.   end;

It´s load well but so, so slow to navigate, it´s not responsive then I try other method(winner method in my opnion), load all images from db into imagelist and draw in oncolumndrawcell:
Code: Pascal  [Select][+][-]
  1. var
  2.   MyEffect:TGraphicsDrawEffect; // units   ImgList, GraphType
  3. begin
  4.   if Sender is TDBGrid then
  5.   begin
  6.     with TDBGrid(Sender) do
  7.     begin
  8.       MyEffect:=gdeShadowed;
  9.       if gdRowHighlight in State then
  10.       begin
  11.         MyEffect:=gdeHighlighted;
  12.       end;
  13.       if Column.Index=0 then  // foto na coluna 0
  14.       begin
  15.         Canvas.FillRect(Rect); // limpando a celula com rect vazio
  16.         i:=dmPrincipal.Colaboradores_Pics.IndexOf(Datasource.Dataset.Fieldbyname('nome_completo').AsString);
  17.         if (i>=0) and (i<=Pred(dmPrincipal.imgList_Colaboradores.Count)) then
  18.         begin
  19.           dmPrincipal.imgList_Colaboradores.Draw(
  20.               Canvas,
  21.               Rect.CenterPoint.x-(dmPrincipal.imgList_EP.Width div 2),
  22.               Rect.CenterPoint.y-(dmPrincipal.imgList_EP.Height div 2),
  23.               i, // imageindex
  24.               MyEffect);  // gdeHighlighted ou gdeShadowed
  25.  
  26.         end;
  27.       end;
  28.           (...)
It´s responsive, it´s fast but I need to wait all images want be loaded before into imagelist using threads.
Before considering method using Imagelist a winner, please, there is a good and fast method to load jpg into a dbgrid cell?

Any help will be wellcome.


« Last Edit: November 25, 2021, 06:20:22 pm by hamacker »

 

TinyPortal © 2005-2018