What is equivalent of Canvas.Pixels[X,Y] in Firemonkey? - delphi

In VCL we can get the color of specific pixel from Canvas or bitmap like this:
Canvas.Pixels[X,Y]
but we have not such a thing for canvas and bitmap in firemonkey components. how can we read or write a specific point on a canvas in FMX?

I presume that you are working with a bitmap, if you wish to operate on pixel data. In which case you use the Map method of the TBitmap class. More details here:
http://www.fmxexpress.com/get-direct-pixel-access-to-bitmaps-in-delphi-xe5-firemonkey-on-android-and-ios/
http://members.adug.org.au/2012/10/05/read-write-image-bitmap-pixels-in-delphi-xe3/
http://docwiki.embarcadero.com/CodeExamples/en/FMX.AlphaColorToPixel_(Delphi)

Related

Delphi - I need to pass a TPrinter canvas to a TBitmap canvas

So I've filled a canvas on my printer object and it prints perfectly. Now I need to save to a file that same canvas that's filled in the printer.canvas. I know I can save a bitmap object and I thought I could just instantiate a bitmap and assign it the printer canvas, but alas, its read-only. This is the line with the error. Anyone has any idea?
bitmapAGuardar.Canvas := Printer.Canvas;
This isn't how to do it, and in fact what you ask can't be done.
Write a function that receives a canvas as its parameter. Have that function perform the necessary drawing. When you need to print to a printer call the function passing the printer canvas. When you need to save to a bitmap, call the function passing the bitmap canvas.
You'll likely need to account for the fact that the printer canvas resolution will be much greater than the resolution you want for the bitmap.

Why are canvas operations not relative to containing object?

In a Windows Firemonkey application, when I issue the following for a rectangle, in the middle of a form:
rect.Canvas.BeginScene;
rect.Canvas.Clear(TAlphaColorRec.White);
rect.Canvas.EndScene
the entire form is painted white.
Was not the case in XE2. Is the case in Delphi 10.
What's the new paradigm I have overlooked?
The canvas of the primitive (e.g TPaintBox and all TShape descendants) controls, is the canvas of the form. The controls draw directly on this canvas. Therefore a call to Control.Canvas.Clear() clears the whole form. Instead of calling Clear you should use the Fill property of the TRectangle, like so:
Rectangle1.Fill.Color := TAlphaColorRec.White;
I can't comment on how it was in Delphi XE2, but there has been many changes to the FMX library, since then. Maybe this is one of them.
Also refer to FireMonkey Component Rendering

How to work with non-visible TImage32

I try to make use of a TImage32 to combine several layers with positions and transparency etc. So I create in runtime a TImage32, set parent to nil, load from file a bitmap and load from file a layer on top of that bitmap. Now I want to save the result, but I seem to be unable to find where the actual result is. If I do the same with creating the TImage32 in designtime, make it visible, the result of the combined bitmaps is in the Buffer field of TImage32, and I can save the result using Image32.Buffer.SaveToFile('test.bmp'). If the component is not visible, the Buffer is an empty bitmap and the combined bitmap seem to be not created.
Can someone shed light on this? How do I combine bitmaps with GR32, save them, but with invisible components?
Thanks a lot!
Willem
You don't need to use visual controls like TImage.
The library you're using graphics32 has all the methods you need.
Use TBitmap32: The Bitmap can be displayed and scaled using its DrawMode, MasterAlpha and StretchFilter properties.
You simply use the MyBitmap.LoadFromFile method to get it.
I suggest you then store your bitmaps in a TObjectList.
Combine them using TBitmap32.Draw{To}, note that you can use the DrawMode to modify the behavior of Draw.
And use the SaveToFile method as usual when done manipulating the bitmap.

How to put a transparent color on a form?

I have a form with an image as the background.
Now I need to put several transparent dark color areas in several areas off the form.
I need not to hide the background. How can I do this?
Standard Delphi control do AFAIK not support that kind of transparency. You therefore have two possiblities:
use third-party components
create your own component (you can derive from an existing one) and override the paint method. In the paint method just draw the correct part of the background image and darken every pixel to get the effect you want.
You can try Delphi 2009/2010 which supports using PNG images. The PNG image format allows for alpha layer transparency, which it sounds it what your looking for. This assumes that your wanting a fixed shape on your form.
EDIT-- For Delphi 2007, you can attempt to use the PNG Components which if I remember correctly do properly handle alpha transparency.
Is the background image and the darker areas the only thing that you want on your form, or do you have other components that should be blended too?
If it's only the background image and the dark areas, I would recommend that you check out Graphics32. It's an image control supporting layers. It should be fairly easy to archive what you want (or what I assume that you want...) from that.

Transparency in TImage

When a new TImage is created it is transparent. After drawing objects to this image I would like to clear them. Note that I need to keep the image transparent as the TImage is being used as an overlay to another image.
Some sort of "clear" function for the TImage would be best. I think I'm missing something simple here, I just could not find any clear function within the TImage menu.
You're not really meant to draw things on a TImage control. You're meant to assign its Picture property and leave it alone. In fact, when you draw on a TImage, you're either drawing transiently by drawing on its Canvas property, or you're modifying the underlying Picture object by drawing on its canvas.
To clear a TImage, simply unassign the Picture property.
Image.Picture := nil;
To draw transient images — something you'll need to repaint whenever the window gets obscured and revealed — use a TPaintBox.

Resources