I inspected Bitmap.cpp and found this function:

static jboolean Bitmap_writeToParcel(JNIEnv* env, jobject,
                                     const SkBitmap* bitmap,
                                     jboolean isMutable, jobject
parcel) {
    if (parcel == NULL) {
        SkDebugf("------- writeToParcel null parcel\n");
        return false;
    }

    android::Parcel* p = android::parcelForJavaObject(env, parcel);

    p->writeInt32(isMutable);
    p->writeInt32(bitmap->config());
    p->writeInt32(bitmap->width());
    p->writeInt32(bitmap->height());
    p->writeInt32(bitmap->rowBytes());

    if (bitmap->getConfig() == SkBitmap::kIndex8_Config) {
        SkColorTable* ctable = bitmap->getColorTable();
        if (ctable != NULL) {
            int count = ctable->count();
            p->writeInt32(count);
            memcpy(p->writeInplace(count * sizeof(SkPMColor)),
                   ctable->lockColors(), count * sizeof(SkPMColor));
            ctable->unlockColors(false);
        } else {
            p->writeInt32(0);   // indicate no ctable
        }
    }

    size_t size = bitmap->getSize();
    bitmap->lockPixels();
    memcpy(p->writeInplace(size), bitmap->getPixels(), size);
    bitmap->unlockPixels();
    return true;
}

I can manually marshal a Bitmap parcel in the proper format, and then
append the custom byte buffer, and then use createFromParcel to create
a bitmap. That gets me indirect access to creating a bitmap directly
from a byte buffer. It's a bit of a hack obviously, and not ideal. Is
there a better way to do this?

On Dec 1, 2:41 pm, Koush <[EMAIL PROTECTED]> wrote:
> I'm trying to populate a create a bitmap from something other than an
> RGBA int array.
> However, the Bitmap creation overloads only take int arrays as inputs.
>
> In particular, I have a byte buffer that is in the R5G6B5 format that
> I want to load directly into a bitmap. The format is supposedly
> supported internally, but I can't figure out how to create the bitmap
> without doing the R5G6B5 to A8R8G8B8 conversion first.
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google
Groups "Android Developers" group.
To post to this group, send email to android-developers@googlegroups.com
To unsubscribe from this group, send email to
[EMAIL PROTECTED]
For more options, visit this group at
http://groups.google.com/group/android-developers?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to