BBitmapStream
allows for the easy conversion of a translator bitmap, the
default Translation Kit bitmap format, to a
BBitmap
.
It's a very limited subclass of
BPositionIO
capable only of reading and writing translator
bitmaps; performing i/o on the object with other types of data can yield
strange results. The main attraction of the class is the
DetachBitmap()
method, which returns the contents of the object as a
BBitmap
.
Most of the time, you won't need to use
BBitmapStream
directly;
BTranslationUtils
contains the functionality required to load images from
files, resources, or general BPositionIOs into
BBitmap
s.
The following snippet illustrates typical usage of
BBitmapStream
sans proper error checking:
BBitmap *FetchBitmap
(char *filename
) {BFile
file
(filename
,B_READ_ONLY
); BTranslatorRoster *roster
=BTranslatorRoster
::Default
();BBitmapStream
stream
; BBitmap *result
=NULL
; if (roster
->Translate
(&file
,NULL
,NULL
, &stream
,B_TRANSLATOR_BITMAP
) <B_OK
) returnNULL
;stream
.DetachBitmap
(&result
); returnresult
; }
You can also initialize the class with a
BBitmap
and use it as input to
BTranslatorRoster::Translate()
to save it in a different format:
voidStoreTranslatorBitmap
(BBitmap *bitmap
, char *filename
, uint32type
) { BTranslatorRoster *roster
=BTranslatorRoster
::Default
();BBitmapStream
stream
(bitmap
); // init with contents of bitmapBFile
file
(filename
,B_CREATE_FILE
|B_WRITE_ONLY
);roster
->Translate
(&stream
,NULL
,NULL
, &file
,type
); }