Recent

Author Topic: [SOLVED] BGRABitmap.Draw - Ignoring X and Y param?  (Read 5739 times)

Dibo

  • Hero Member
  • *****
  • Posts: 1048
[SOLVED] BGRABitmap.Draw - Ignoring X and Y param?
« on: April 13, 2012, 02:21:43 pm »
Hi,

I want draw BGRABitmap on canvas with some offset, but Draw and DrawPart are ignoring X and Y params (even if I use overloaded method with TRect instead of X/Y). Is this a bug or are they for something else (I thought that they working similar like X,Y offset in TBGRABitmap.PutImage method)? This is my test code:
Code: Pascal  [Select][+][-]
  1. procedure TForm1.FormPaint(Sender: TObject);
  2. var
  3.   b: TBGRABitmap;
  4.   r: TRect;
  5. begin
  6.   b := TBGRABitmap.Create(100,100);
  7.   r := b.ClipRect;
  8.   b.Rectangle(b.ClipRect,clblack);
  9.   b.Draw(Self.Canvas,200,200,False);
  10.   b.Free;
  11. end;
  12.  
Rectangle should be offset by 200,200 but it always start from 0,0.
I have stable BGRABitmap 5.6, FPC 2.6.0 Stable, Lazarus 0.9.31 from SVN builded on QT interface

BTW: Why code=pascal doesn't highlight pascal syntax any more on this forum? I noticed this when forum get new layout/engine.

Regards, Dibo
« Last Edit: April 14, 2012, 12:02:30 pm by Dibo »

circular

  • Hero Member
  • *****
  • Posts: 4217
    • Personal webpage
Re: BGRABitmap.Draw - Ignoring X and Y param?
« Reply #1 on: April 14, 2012, 12:49:47 am »
This works fine on Windows. There may be a bug in QT code.

Oh I found it.

In bgraqtbitmap.pas, replace :
Code: [Select]
procedure TBGRAQtBitmap.SlowDrawTransparent(ABitmap: TBGRADefaultBitmap;
  ACanvas: TCanvas; ARect: TRect);
begin
  ACanvas.Draw(0,0, ABitmap.Bitmap);
end;

By this
Code: [Select]
procedure TBGRAQtBitmap.SlowDrawTransparent(ABitmap: TBGRADefaultBitmap;
  ACanvas: TCanvas; ARect: TRect);
begin
  ACanvas.StretchDraw(ARect, ABitmap.Bitmap);
end;

Does it work ?
Conscience is the debugger of the mind

Dibo

  • Hero Member
  • *****
  • Posts: 1048
Re: BGRABitmap.Draw - Ignoring X and Y param?
« Reply #2 on: April 14, 2012, 12:02:15 pm »
Works. Thanks! :)

Dibo

  • Hero Member
  • *****
  • Posts: 1048
Re: [SOLVED] BGRABitmap.Draw - Ignoring X and Y param?
« Reply #3 on: April 14, 2012, 12:56:47 pm »
But are you sure that it should be StretchDraw? Because now it stretch bitmap to the rect. Maybe it should be something like this? It works too.
ACanvas.Draw(ARect.Left,ARect.Top, ABitmap.Bitmap);

User137

  • Hero Member
  • *****
  • Posts: 1791
    • Nxpascal home
Re: [SOLVED] BGRABitmap.Draw - Ignoring X and Y param?
« Reply #4 on: April 14, 2012, 01:04:54 pm »
In that case function parameter should be a TPoint, not TRect. No point sending 4 values where only 2 are used.

circular

  • Hero Member
  • *****
  • Posts: 4217
    • Personal webpage
Re: [SOLVED] BGRABitmap.Draw - Ignoring X and Y param?
« Reply #5 on: April 14, 2012, 10:29:13 pm »
Normally, the TRect should be automatically adjusted to the right size when you call the usual Draw method. It is not the case ?
Conscience is the debugger of the mind

Dibo

  • Hero Member
  • *****
  • Posts: 1048
Re: [SOLVED] BGRABitmap.Draw - Ignoring X and Y param?
« Reply #6 on: April 14, 2012, 11:24:14 pm »
You are right. I had wrong code. Overloaded draw method with TRect should stretch image, this is logical. So I used draw method with X and Y param and my image doesn't stretch, it is just offset and cut like I wanted. It was a wrong interpretation on my part. Problem solved

circular

  • Hero Member
  • *****
  • Posts: 4217
    • Personal webpage
Re: [SOLVED] BGRABitmap.Draw - Ignoring X and Y param?
« Reply #7 on: April 15, 2012, 12:42:25 pm »
It's cool that your problem is solved.

I've update on subversion the QT code with the correct code.
Conscience is the debugger of the mind

 

TinyPortal © 2005-2018