The Translation Kit Table of Contents | The Translation Kit Index |
Derived from: public BPositionIO
Declared in: be/translation/BitmapStream.h
Library: libtranslation.so
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 BBitmaps.
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) return NULL; stream.DetachBitmap(&result); return result; }
You can also initialize the class with a BBitmap and use it as input to BTranslatorRoster::Translate() to save it in a different format:
void StoreTranslatorBitmap(BBitmap *bitmap, char *filename, uint32 type) { BTranslatorRoster *roster = BTranslatorRoster::Default(); BBitmapStream stream(bitmap); // init with contents of bitmap BFile file(filename, B_CREATE_FILE | B_WRITE_ONLY); roster->Translate(&stream, NULL, NULL, &file, type); }
|
Creates a new instance of BBitmapStream. If map is NULL, the stream is initialized to be empty. Otherwise, the BBitmap is converted to a translator bitmap and placed in the stream. The application shares the BBitmap with the BBitmapStream object. It therefore shouldn't delete the BBitmap without first calling DetachBitmap().
|
Frees all memory allocated by the BTranslatorRoster.
|
Returns, in outMap, a BBitmap representing the image contained in the BBitmapStream. Once DetachBitmap() has been called, no further operations should be performed on the BBitmapStream.
RETURN CODES
. Success.
|
These methods provide the implementation for the BPositionIO. The class functions identically to BPositionIO with the exception of ReadAt() and WriteAt(), which read and write only translator bitmaps as described in the class introduction.
See also: BPositionIO
|
Returns the number of bytes in the translator bitmap in the stream.
The Translation Kit Table of Contents | The Translation Kit Index |
Copyright © 2000 Be, Inc. All rights reserved..