Steema Issues Database

Note: This database is for bugs and wishes only. For technical support help, if you are a customer please visit our online forums;
otherwise you can use StackOverflow.
Before using this bug-tracker we recommend a look at this document, Steema Bug Fixing Policy.



Bug 2442

Summary: Grid doesn't draw bitmaps with transparent background
Product: TeeGrid for Delphi Reporter: dean.mustakinov
Component: GridAssignee: david berneda <david>
Status: RESOLVED FIXED    
Severity: major CC: marc
Priority: ---    
Version: unspecified   
Target Milestone: ---   
Hardware: PC   
OS: Windows   
Chart Series: --- Delphi / C++ Builder RAD IDE Version:

Description dean.mustakinov 2021-06-28 23:18:45 EDT
When drawing custom images in Column.OnDraw event using Data.Painter.Draw method there is no way to specify that image should have a transparent background.
I have fixed this for VCL/Windows version with following changes:
Tee.Format.pas:
uses
  {.$IFDEF FPC} // DM CHANGE
  Graphics,
  {.$ELSE} // DM CHANGE
  {$IFNDEF NOUITYPES}
  System.UITypes,
  {$ENDIF}

  {$IF CompilerVersion>=33}
  {System.}Generics.Collections,
  {$IFEND}

  {.$ENDIF} // DM CHANGE

  {System.}Classes;

TPicture=class(TPersistentChange)
  protected
    Internal,
    Original  : TObject;

    {$IFDEF AUTOREFCOUNT}[weak]{$ENDIF}
    TagObject : TObject;

    procedure FreeInternal;
  public
    Stretch : Boolean;
    Transparent : Boolean; // DM CHANGE
    TransparentColor : TColor; // DM CHANGE
    TransparentMode : TTransparentMode; // DM CHANGE

    Constructor Create(const AChanged:TNotifyEvent); override;

    Destructor Destroy; override;

    procedure Clear;

    // Workaround for FMX TBitmap issue, see FMXTee.Grid.pas
    class function NewPicture:TPersistent; virtual;

    procedure SetGraphic(const AObject:TObject);
  end;

VCLTee.Painter.GdiPlus.pas: 
procedure TGdiPlusPainter.DrawImage(const APicture: TPicture; const AImage:TGPImage; const ARect:TGPRectF);
// DM CHANGE START
var
  loImgAttr: TGPImageAttributes;
  tpcol: TGPColor;
  srcrect: TGPRectF;
  srcunit: TUnit;
begin
  // DM CHANGE START
  loImgAttr := nil;
  try
    if APicture.Transparent and (AImage is TGPBitmap) then begin
      if APicture.TransparentMode = tmFixed then tpcol := TAlphaColors.ColorToRGB(APicture.TransparentColor)
      else TGPBitmap(AImage).GetPixel(0, 0, tpcol);
      loImgAttr := TGPImageAttributes.Create;
      loImgAttr.SetColorKey(tpcol, tpcol, ColorAdjustTypeBitmap);
    end;
    AImage.GetBounds(srcrect, srcunit);
    if APicture.Stretch then
       IPlus.DrawImage(AImage,ARect,srcrect.X,srcrect.Y,srcrect.Width,srcrect.Height,UnitPixel,loImgAttr)
    else
       IPlus.DrawImage(AImage,ARect,0,0,Trunc(ARect.Width-1),Trunc(ARect.Height-1),UnitPixel,loImgAttr);
  finally
    FreeAndNil(loImgAttr);
  end;
  // DM CHANGE END
end;
Comment 1 marc meumann 2021-09-14 07:27:43 EDT
Thank you for you input Dean, we'll check to include your code