Drawing bitmap on Windows

TeeChart FireMonkey (Windows,OSX,iOS & Android) for Embarcadero RAD Studio, Delphi and C++ Builder (XE5+)
Post Reply
Atmapuri
Newbie
Newbie
Posts: 15
Joined: Wed Jul 31, 2013 12:00 am

Drawing bitmap on Windows

Post by Atmapuri » Wed Nov 27, 2013 10:47 am

Hi!

I am drawing a bitmap on TeeChart in FireMonkey for Windows:

var FBitmap: FMX.Graphics.TBitmap;
...
ParentChart.Canvas.StretchDraw(Rf,FBitmap)
...

The bitmap gets drawn, but the FBitmap.PixelFormat Property is ignored. The bitmap is drawn in the CMYK color mode it seems. (At least those are the colors I get to see). How can I get 4 byte RGB color format Bitmap displayed by TeeChart property?
Specifically:

TPixelFormat.pfA8R8G8B8;

Second: What to do to make the same code work on iOS, Android and OSx.

Thanks!
Atmapuri

Narcís
Site Admin
Site Admin
Posts: 14730
Joined: Mon Jun 09, 2003 4:00 am
Location: Banyoles, Catalonia
Contact:

Re: Drawing bitmap on Windows

Post by Narcís » Wed Nov 27, 2013 3:00 pm

Hi Atmapuri,

We need to investigate this thoroughly. TeeChart only calls Firemonkey's:

Code: Select all

  FCanvas.DrawBitmap(Graphic,TeeRect(0,0,Graphic.Width,Graphic.Height),
                     ARect,Opacity,FStretchQuality=sqLow);
New Chart1.Canvas.StretchQuality property controlls last parameter at the signature above. At Quality Central there are several open bugs aboug DrawBitmap.

Could you please attach a simple example project we can run "as-is" to reproduce the problem here?
Best Regards,
Narcís Calvet / Development & Support
Steema Software
Avinguda Montilivi 33, 17003 Girona, Catalonia
Tel: 34 972 218 797
http://www.steema.com
Image Image Image Image Image Image
Instructions - How to post in this forum

Atmapuri
Newbie
Newbie
Posts: 15
Joined: Wed Jul 31, 2013 12:00 am

Re: Drawing bitmap on Windows

Post by Atmapuri » Fri Nov 29, 2013 3:05 pm

Dear Narcis,

Any example would do fine, where you can do:

bitmap.Size(2,2);
bitmap.Map(...,bitData);
...
P := bitData.Scanline[0];
P[0].A := 12;
P[0].R := 25;
P[0].G := 36;
P[0].B := 50;
P[1]...

bitmap.Unmap(...);
tChart.Canvas.StretchDraw(bitmap, tChart.ClientRect);

Thanks!
Atmapuri

David Berneda
Site Admin
Site Admin
Posts: 83
Joined: Wed Nov 12, 2003 5:00 am
Location: Girona, Catalonia
Contact:

Re: Drawing bitmap on Windows

Post by David Berneda » Mon Dec 02, 2013 11:25 am

Hi Atmapuri

Just did the attached test project and it looks fine to me (both with high and low stretch blending modes).

regards
david
Attachments
StretchBitmap.zip
(4.49 KiB) Downloaded 1761 times

Atmapuri
Newbie
Newbie
Posts: 15
Joined: Wed Jul 31, 2013 12:00 am

Re: Drawing bitmap on Windows

Post by Atmapuri » Fri Dec 06, 2013 8:22 pm

Dear David,

Thank you for the example. However, in the question there is specifically mentioned the Scanline. I cannot use SetPixel, because it is orders of magnitude too slow.
Do you always use SetPixel with FireMonkey? That would mean that you have not figured out how to work with Scanline yet either?

Thanks!
Atmapuri

David Berneda
Site Admin
Site Admin
Posts: 83
Joined: Wed Nov 12, 2003 5:00 am
Location: Girona, Catalonia
Contact:

Re: Drawing bitmap on Windows

Post by David Berneda » Tue Dec 10, 2013 11:43 am

There are several usages of ScanLine already in FireMonkey TTeeCanvas, of course.

I've changed the example using scanline, same (ok) results, see below.

TeeCanvas StretchDraw simply passes the bitmap to FireMonkey's DrawBitmap method, there is nothing changed:

procedure TTeeCanvas3D.StretchDraw(const ARect: TRect; const Graphic: TGraphic);
begin
FCanvas.DrawBitmap(Graphic,TeeRect(0,0,Graphic.Width,Graphic.Height),
ARect,Opacity,FStretchQuality=sqLow);
end;

regards
david

...
var P : PAlphaColorArray;
...

b:=TBitmap.Create(2,2);

if b.Map(TMapAccess.maWrite,tmp) then
try
P:=tmp.GetScanline(0);

P[0]:=TAlphaColors.Red;
P[1]:=TAlphaColors.Green;

P:=tmp.GetScanline(1);

P[0]:=TAlphaColors.Blue;
P[1]:=TAlphaColors.Yellow;


{
tmp.SetPixel(0,0,TAlphaColors.Red);
tmp.SetPixel(0,1,TAlphaColors.Green);
tmp.SetPixel(1,0,TAlphaColors.Blue);
tmp.SetPixel(1,1,TAlphaColors.Yellow);
}
finally
b.Unmap(tmp);
end;

Chart1.DelphiCanvas.BeginScene;
Chart1.Canvas.StretchDraw(Chart1.AbsoluteRect,b);
Chart1.DelphiCanvas.EndScene;

Atmapuri
Newbie
Newbie
Posts: 15
Joined: Wed Jul 31, 2013 12:00 am

Re: Drawing bitmap on Windows

Post by Atmapuri » Thu Jan 02, 2014 4:47 pm

Hello David,

The problem was resolved after I learned that:

1.) The Alpha field in RGB needs to be set to $FF (not transparent).
2.) The structure for the color has reversed storage format, Instead of RGB for VCL (24bit), it is ABGR for Firemonkey. (32 bit)

Because I was constructing colors from scratch I lost my compass for a while.
It took some time to make the code work with Alpha values of each color set to $FF.

Thanks for the assistance.

Kind Regards!
Atmapuri

Post Reply