Jump to content


PeterNu

Member Since 22 Apr 2022
Offline Last Active May 09 2022 12:08 PM
-----

Posts I've Made

In Topic: Event OnCustomDrawCell not fired

03 May 2022 - 11:22 AM

Hello,

 

thanks for your mail.

 

The graphic column is the result of an query. The datatype is ftBlob not ftGraphic.

 

I make in your source a short modification:

 

     if DataField.DataType = ftGraphic then
 
to
 
     if DataField.DataType in [ftGraphic,ftBlob] then
 
 
The images are displayed now.
 
procedure TForm1.NextDBGrid61GetBlobGraphic(Sender: TObject; Field: TField;var Graphic: TGraphic);
var PngImage:  TPngImage;
begin
  if Field.IsBlob then
  begin
    PngImage:=TPngImage.Create;
    try
      PngImage.Assign(Field);
      PngImage.Transparent:=True;
      Graphic:=PngImage;
    finally
      //PngImage.Free;  
    end;
  end;
end;
 
 
But now we have a strange behavior. When I move the mouse pointer over the grid an EOutOfResources exception occurce.
 
Maybe its better you fire the OnCustomDrawCell event. Then I can paint die PNG image into the cell.

In Topic: Event OnCustomDrawCell not fired

28 April 2022 - 09:20 PM

Delphi 11 Alexandria.

Thank you for your support.

In Topic: Event OnCustomDrawCell not fired

27 April 2022 - 10:21 AM

Ok I assign the field to the PngImage like this:

 

  if ACol=0 then
  begin
    PngImage:=TPngImage.Create;
    try
      PngImage.Assign(TNxDBGraphicColumn6(NextDBGrid61.Columns[ACol]).DataBinding.Field);
      PngImage.Transparent:=True;
      DeltaX:=((CellRect.Right-CellRect.Left)-PngImage.Width) div 2;
      DeltaY:=((CellRect.Bottom-CellRect.Top)-PngImage.Height) div 2;
      NextDBGrid61.Canvas.Brush.Color:=clWhite;
      NextDBGrid61.Canvas.FillRect(CellRect);
      NextDBGrid61.Canvas.Draw(CellRect.Left+DeltaX,CellRect.Top+DeltaY,PngImage);
    finally
      PngImage.Free;
    end;
  end;
 
But the result is always the same. Each cell in the column display the same picture.
I need to display a image for each row. :-(

In Topic: Event OnCustomDrawCell not fired

27 April 2022 - 09:37 AM

That with the event is a good idea. Also the native support of PNG would be great, but until then I need a workaround.

 

How can I assign the content of TNxDBGraphicColumn6(NextDBGrid61.Columns[ACol]).DataBinding.Field to my PngImage?


In Topic: Event OnCustomDrawCell not fired

26 April 2022 - 05:38 PM

The PNG data is inside a blob field and I use this code:

 

procedure TForm1.NxDBGraphicColumn1DrawContent(Sender: TObject; ACol,
  ARow: Integer; CellRect: TRect; State: TNxCellPaintingState);
var PngImage:      TPngImage;
    DeltaX,DeltaY: Integer;
    BlobStream:    TStream;
begin
  if ACol=0 then
  begin
    if UniQuery1.FindField('thumbnail')<>nil then
    begin
      if UniQuery1.FieldByName('thumbnail').IsBlob and not UniQuery1.FieldByName('thumbnail').IsNull then
      begin
        BlobStream:=UniQuery1.CreateBlobStream(UniQuery1.FieldByName('thumbnail'),bmRead);
        try
          if BlobStream.Size>0 then
          begin
            PngImage:=TPngImage.Create;
            try
              Blobstream.Position:=0;
              PngImage.LoadFromStream(BlobStream);
              PngImage.Transparent:=True;
              DeltaX:=((CellRect.Right-CellRect.Left)-PngImage.Width) div 2;
              DeltaY:=((CellRect.Bottom-CellRect.Top)-PngImage.Height) div 2;
              NextDBGrid61.Canvas.Draw(CellRect.Left+DeltaX,CellRect.Top+DeltaY,PngImage);
            finally
              PngImage.Free;
            end;
          end;
        finally
          BlobStream.Free;
        end;
      end;
    end;
  end;
end;
 
But each row display the same image and not the blob data of the cell.