Contains a bitmap resource type

This unit contains , a TAbstractResource descendant specialized in handling resource of type RT_BITMAP.

Adding this unit to a program's uses clause registers class for type RT_BITMAP with TResourceFactory.

Bitmap resource type

This class represents a resource of type RT_BITMAP.

A bitmap resource contents is very similar to a BMP file. However some differences exists, so RawData is not appropriate if you need to read and write BMP data. Instead, BitmapData property gives access to a BMP file-like stream.

This class doesn't allow its type to be changed to anything else than RT_BITMAP. Attempts to do so result in a EResourceDescChangeNotAllowedException.
BitmapData TAbstractResource.RawData
Creates a new bitmap resource

Please note that aType parameter is not used, since this class always uses RT_BITMAP as type.

Ignored. Can be nil. The name of the resource Sets a custom stream as the underlying stream for BitmapData

This method allows the user to use a custom stream as the underlying stream for BitmapData. This is useful when you want a to be created from a bmp file for which you have a stream.

Sample code

This code creates a resource containing a bitmap

var aName : TResourceDesc; aRes : TBitmapResource; aFile : TFileStream; Resources : TResources; begin Resources:=TResources.Create; aName:=TResourceDesc.Create('MYBITMAP'); aRes:=TBitmapResource.Create(nil,aName); //type is always RT_BITMAP aName.Free; //not needed anymore aFile:=TFileStream.Create('mybitmap.bmp',fmOpenRead or fmShareDenyNone); aRes.SetCustomBitmapDataStream(aFile); Resources.Add(aRes); Resources.WriteToFile('myresource.res'); Resources.Free; //it destroys aRes as well. aFile.Free; end;
TAbstractResource.UpdateRawData
The custom stream to use as the underlying BitmapData stream Resource data as a BMP stream

BitmapData property gives access to resource data in a BMP file-like stream, unlike RawData.

BitmapData does not create a copy of RawData so memory usage is generally kept limited.

You can also set a custom stream as the underlying stream for BitmapData via SetCustomBitmapDataStream, much like SetCustomRawDataStream does for RawData. This is useful when you want a to be created from a bmp file for which you have a stream.

If you need to access RawData after you modified BitmapData, be sure to call UpdateRawData first. This isn't needed however when resource is written to a stream, since TResources takes care of it.
TAbstractResource.RawData TAbstractResource.UpdateRawData