HaikuDepot: Added ability to load archived BBitmaps resourced.
* SharedBitmap should probably be moved into its own file. * Untested as of yet.
This commit is contained in:
@@ -9,6 +9,7 @@
|
|||||||
|
|
||||||
#include <Application.h>
|
#include <Application.h>
|
||||||
#include <Bitmap.h>
|
#include <Bitmap.h>
|
||||||
|
#include <DataIO.h>
|
||||||
#include <IconUtils.h>
|
#include <IconUtils.h>
|
||||||
#include <MimeType.h>
|
#include <MimeType.h>
|
||||||
#include <Resources.h>
|
#include <Resources.h>
|
||||||
@@ -106,22 +107,45 @@ SharedBitmap::_CreateBitmapFromResource(int32 size) const
|
|||||||
size_t dataSize;
|
size_t dataSize;
|
||||||
const void* data = resources.LoadResource(B_VECTOR_ICON_TYPE, fResourceID,
|
const void* data = resources.LoadResource(B_VECTOR_ICON_TYPE, fResourceID,
|
||||||
&dataSize);
|
&dataSize);
|
||||||
if (data == NULL)
|
if (data != NULL) {
|
||||||
return NULL;
|
BBitmap* bitmap = new BBitmap(BRect(0, 0, size - 1, size - 1), 0,
|
||||||
|
B_RGBA32);
|
||||||
BBitmap* bitmap = new BBitmap(BRect(0, 0, size - 1, size - 1), 0, B_RGBA32);
|
status = bitmap->InitCheck();
|
||||||
status = bitmap->InitCheck();
|
if (status == B_OK) {
|
||||||
if (status == B_OK) {
|
status = BIconUtils::GetVectorIcon(
|
||||||
status = BIconUtils::GetVectorIcon(
|
reinterpret_cast<const uint8*>(data), dataSize, bitmap);
|
||||||
reinterpret_cast<const uint8*>(data), dataSize, bitmap);
|
};
|
||||||
};
|
|
||||||
|
if (status != B_OK) {
|
||||||
if (status != B_OK) {
|
delete bitmap;
|
||||||
delete bitmap;
|
bitmap = NULL;
|
||||||
bitmap = NULL;
|
}
|
||||||
|
|
||||||
|
return bitmap;
|
||||||
}
|
}
|
||||||
|
|
||||||
return bitmap;
|
data = resources.LoadResource(B_MESSAGE_TYPE, fResourceID, &dataSize);
|
||||||
|
if (data != NULL) {
|
||||||
|
BMemoryIO stream(data, dataSize);
|
||||||
|
|
||||||
|
// Try to read as an archived bitmap.
|
||||||
|
BMessage archive;
|
||||||
|
status = archive.Unflatten(&stream);
|
||||||
|
if (status != B_OK)
|
||||||
|
return NULL;
|
||||||
|
|
||||||
|
BBitmap* bitmap = new BBitmap(&archive);
|
||||||
|
|
||||||
|
status = bitmap->InitCheck();
|
||||||
|
if (status != B_OK) {
|
||||||
|
delete bitmap;
|
||||||
|
bitmap = NULL;
|
||||||
|
}
|
||||||
|
|
||||||
|
return bitmap;
|
||||||
|
}
|
||||||
|
|
||||||
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user