1 Introduction

Traditionally bitmaps in Graphics32 have been using resources managed by the Windows GDI. While this is feasible for most usage scenarios in Windows there are some that require certain less resource-restricted approaches like handle-less bitmaps or bitmaps that rely on memory-mapped files. Prior to Graphics32 1.9 several community-driven patches existed that added these features.
With the arrival of broader platform support in Graphics32 we are separating the memory management as well as OS or graphics subsystem specific methods from the generic methods in TBitmap32 and move these portions into so called back-end classes.

2 Approach and compatibility

In order to keep backwards compatibility the TBitmap32 class still exposes the same external interface. In order to get a clean cut from the platform specific methods and properties we implemented a new in-between class TCustomBitmap32 which is truly platform agnostic and relies solely on the associated back-end class to handle its needs. As a matter of fact TCustomBitmap32 is missing all Text, Canvas and Handle methods. Back-ends may implement predefined interfaces to implement the functionality.

The back-end instance is switchable during the lifecycle of a TCustomBitmap32 instance. Conversion to the new back-end instance is handled transparently, i.e. without loosing the bitmap's surface contents. For instance this allows for temporarily switching a handle-less memory-only bitmap to a GDI bitmap with handle and vice versa. TCustomBitmap32 exposes the current back-end via its Backend property.

Code example (Switching back-ends)
  MyBitmap := TBitmap32.Create;
  TMMFBackend.Create(MyBitmap); // Switch to a handle-less memory mapped file back-end...
  MyBitmap.SetSize(5000, 5000);

  // Draw onto your new big bitmap...
  // Note: No text or canvas drawing is allowed because TMMFBackend does not implement those operations.
  // Use TGDIMMFBackend instead...

  TGDIBackend.Create(MyBitmap); // Switch to a GDI back-end and convert the current buffer...

3 Class and interface overview

Currently Graphics32 ships with the following back-end classes which are subclasses of TBackend and implement several interfaces (see below):

By default TBitmap32 now uses the back-end class TGDIBackend on Delphi/VCL/Windows and TLCLBackend on FreePascal/LCL/[supported OS (see above)].

Each of these back-ends may or may not implement certain pre-defined interfaces which can be queried for at runtime either directly via the back-end or indirectly via the bitmap instance:

Please note: Most of the methods and properties left in TBitmap32 query the back-end for these specific interfaces. Failing to implement the required interfaces in the back-end class will cause the method call or property read to fail with an exception. We recommend to change your custom routines or methods to use TCustomBitmap32 instead of TBitmap32 wherever possible.


See Also

TBackend, TBitmap32, TCustomBitmap32, TCustomBitmap32.Backend, IBitmapContextSupport, ICanvasSupport, ICopyFromBitmapSupport, IDeviceContextSupport, IFontSupport, IPaintSupport, ITextSupport, TMemoryBackend, TMMFBackend, TGDIBackend, TGDIMemoryBackend, TGDIMMFBackend