Page 1 of 1

Drawing bitmap on Windows

Posted: Wed Nov 27, 2013 10:47 am
by 16566656
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

Re: Drawing bitmap on Windows

Posted: Wed Nov 27, 2013 3:00 pm
by narcis
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?

Re: Drawing bitmap on Windows

Posted: Fri Nov 29, 2013 3:05 pm
by 16566656
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

Re: Drawing bitmap on Windows

Posted: Mon Dec 02, 2013 11:25 am
by David
Hi Atmapuri

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

regards
david

Re: Drawing bitmap on Windows

Posted: Fri Dec 06, 2013 8:22 pm
by 16566656
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

Re: Drawing bitmap on Windows

Posted: Tue Dec 10, 2013 11:43 am
by David
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;

Re: Drawing bitmap on Windows

Posted: Thu Jan 02, 2014 4:47 pm
by 16566656
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