Recent

Author Topic: TBGRABitmap uses TCanvas rather than TBGRACanvas  (Read 3246 times)

abtaylr

  • Full Member
  • ***
  • Posts: 107
TBGRABitmap uses TCanvas rather than TBGRACanvas
« on: July 07, 2016, 11:34:08 pm »
I am using TBGRABitmap, but when I use one of the procedures I get an error that it expects TBitmap rather than TBGRABitmap.

Code: Pascal  [Select][+][-]
  1.      PrevFrameImage:=TBGRABitmap.Create;
  2.      PrevSubImage:=TBGRABitmap.Create;
  3.      . . . .
  4.  

Later, I input PrevSubImage into another TBGRABitmap like this:

Code: Pascal  [Select][+][-]
  1.             CharMatrix.SubBmp.Canvas.Draw(0,0,PrevSubImage);
  2.             CutRect := CharMatrix.CutValidRect(CharMatrix.SubBmp, 1);
  3.             VobProcess.ReallySkip := False;
  4.             ImageVideo.Canvas.Draw(0,0,PrevFrameImage);

The error refers to CharMatrix.SubBmp.Canvas.Draw:

      unit21.pas(643,59) Error: Incompatible type for arg no. 3: Got "TBGRAGtkBitmap", expected "TGraphic"

Under the Class -- CharMatrix, SubBmp is created like this:

Code: Pascal  [Select][+][-]
  1.     TCharacterMatrix = Class
  2.         . . . .
  3.        SubBmp : TBGRABitmap;
  4.        . . . .
  5.     end;
  6.  
  7.    implementation
  8.  
  9.     constructor TCharacterMatrix.Create;overload;
  10.     begin
  11.       . . . .
  12.       SubBmp := TBGRABitmap.Create;
  13.      . . . .
  14.     end;
  15.  

CharMatrix is an instance of the TCharacterMatrix Class.  I make extensive use of SubBmp within this class in numerous methods. The place where is the error is made is an input point in the form where CharMatrix has the bitmap introduced.

Following the error, the following note is found:

    canvas.inc(20,19) Hint: Found declaration: Draw(LongInt;LongInt;TGraphic);

Shouldn't that refer to BGRACanvas? I would think that BGRABitmap uses BGRACanvas. Am I missing something?

The note is referring to the TCanvas methods:

Code: Pascal  [Select][+][-]
  1. procedure TCanvas.Draw(X, Y: Integer; SrcGraphic: TGraphic);
  2. var
  3.   ARect: TRect;
  4. begin
  5.   if not Assigned(SrcGraphic) then exit;
  6.   ARect:=Bounds(X,Y,SrcGraphic.Width,SrcGraphic.Height);
  7.   StretchDraw(ARect,SrcGraphic);
  8. end;

If it was pointed to TBGRACanvas, it should refer to:

Code: Pascal  [Select][+][-]
  1. procedure TBGRACanvas.Draw(X, Y: Integer; SrcBitmap: TBGRACustomBitmap);
  2. begin
  3.   FBitmap.PutImage(X,Y,SrcBitmap,dmDrawWithTransparency);
  4. end;

or maybe:

Code: Pascal  [Select][+][-]
  1. procedure TBGRAGtkBitmap.Draw(ACanvas: TCanvas; x, y: integer; Opaque: boolean);
  2. begin
  3.   if self = nil then
  4.     exit;
  5.   if Opaque then
  6.     DrawOpaque(ACanvas, Rect(X, Y, X + Width, Y + Height))
  7.   else
  8.     DrawTransparent(ACanvas, Rect(X, Y, X + Width, Y + Height));
  9. end;
  10.  
  11. procedure TBGRAGtkBitmap.Draw(ACanvas: TCanvas; Rect: TRect; Opaque: boolean);
  12. begin
  13.   if self = nil then
  14.     exit;
  15.   if Opaque then
  16.     DrawOpaque(ACanvas, Rect)
  17.   else
  18.     DrawTransparent(ACanvas, Rect);
  19. end;

As you can see these refer to TCanvas.

I am using Kubuntu 16.04 LTS 64bit.  FPC 3.0.1 (fixes branch)  Lazarus 1.6.1 (fixes branch).
« Last Edit: July 07, 2016, 11:51:22 pm by abtaylr »

lainz

  • Hero Member
  • *****
  • Posts: 4473
    • https://lainz.github.io/
Re: TBGRABitmap uses TCanvas rather than TBGRACanvas
« Reply #1 on: July 07, 2016, 11:45:06 pm »
Quote
Later, I input PrevSubImage into another TBGRABitmap like this:

Code: Pascal  [Select]
            CharMatrix.SubBmp.Canvas.Draw(0,0,PrevSubImage);
            CutRect := CharMatrix.CutValidRect(CharMatrix.SubBmp, 1);
            VobProcess.ReallySkip := False;
            ImageVideo.Canvas.Draw(0,0,PrevFrameImage);

That's not the way to input PrevSubImage into other. You need to use PutImage, BlendImage or BlendImageOver methods. Don't use Canvas.Draw.


abtaylr

  • Full Member
  • ***
  • Posts: 107
Re: TBGRABitmap uses TCanvas rather than TBGRACanvas
« Reply #2 on: July 08, 2016, 12:11:58 am »
Excellent! A much better method than what I was doing!  Thx.

circular

  • Hero Member
  • *****
  • Posts: 4224
    • Personal webpage
Re: TBGRABitmap uses TCanvas rather than TBGRACanvas
« Reply #3 on: July 08, 2016, 03:27:46 pm »
If you would like to use functions similar to TCanvas, you can use the CanvasBGRA property that provides functions with similar to TCanvas.

The property Canvas is provided only for compatibility with TBitmap and but it is recommended to avoid using it and to use functions like PutImage as Lainz suggests or the properties CanvasBGRA or Canvas2D.
Conscience is the debugger of the mind

 

TinyPortal © 2005-2018