CGBitmapImageContext and CGBitmapInfo + CGImageAlphaInfo

468 views
Skip to first unread message

Vitaly

unread,
May 15, 2014, 3:46:39 AM5/15/14
to rob...@googlegroups.com
I want to create CGBitmapContext from Java, I see "create" static method mapped to CGBitmapContextCreate(), but there is a problem passing parameters. From Apple docs:

> bitmapInfo

> Constants that specify whether the bitmap should contain an alpha channel, the alpha channel’s relative location in a pixel, and information about whether the pixel components are floating-point or integer values. The constants for specifying the alpha channel information are declared with the CGImageAlphaInfo type but can be passed to this parameter safely.

I see CGBitmapInfo and CGImageAlphaInfo enums in cocoatouch bindings, but "create" method allows only CGBitmapInfo, where it should accept mask of CGBitmapInfo and CGImageAlphaInfo constants. Is it possible to fix?
Message has been deleted

Max Morawski

unread,
May 16, 2014, 5:58:39 PM5/16/14
to rob...@googlegroups.com
I agree it would be nice to have a tidy API for this but in the mean time you can define the constants yourself:

    public static final int kCGImageAlphaNone = 0; /* For example, RGB. */
    public static final int kCGImageAlphaPremultipliedLast = 1; /* For example, premultiplied RGBA */
    public static final int kCGImageAlphaPremultipliedFirst = 2; /* For example, premultiplied ARGB */
    public static final int kCGImageAlphaLast = 3; /* For example, non-premultiplied RGBA */
    public static final int kCGImageAlphaFirst = 4; /* For example, non-premultiplied ARGB */
    public static final int kCGImageAlphaNoneSkipLast = 5; /* For example, RBGX. */
    public static final int kCGImageAlphaNoneSkipFirst = 6; /* For example, XRGB. */
    public static final int kCGImageAlphaOnly = 7; /* No color data, alpha data only */

    public static final int kCGBitmapAlphaInfoMask = 0x1F;
    public static final int kCGBitmapFloatComponents = (1 << 8);
    public static final int kCGBitmapByteOrderMask = 0x7000;
    public static final int kCGBitmapByteOrderDefault = (0 << 12);
    public static final int kCGBitmapByteOrder16Little = (1 << 12);
    public static final int kCGBitmapByteOrder32Little = (2 << 12);
    public static final int kCGBitmapByteOrder16Big = (3 << 12);
    public static final int kCGBitmapByteOrder32Big = (4 << 12);

    // from https://developer.apple.com/library/mac/documentation/GraphicsImaging/Conceptual/drawingwithquartz2d/dq_context/dq_context.html
    // Table 2-1  Pixel formats supported for bitmap graphics contexts (iOS only)
    // CS    Pixel format and bitmap information constant
    // Null  8 bpp, 8 bpc, kCGImageAlphaOnly
    // Gray  8 bpp, 8 bpc,kCGImageAlphaNone
    // Gray  8 bpp, 8 bpc,kCGImageAlphaOnly
    // RGB   16 bpp, 5 bpc, kCGImageAlphaNoneSkipFirst
    // RGB   32 bpp, 8 bpc, kCGImageAlphaNoneSkipFirst
    // RGB   32 bpp, 8 bpc, kCGImageAlphaNoneSkipLast
    // RGB   32 bpp, 8 bpc, kCGImageAlphaPremultipliedFirst
    // RGB   32 bpp, 8 bpc, kCGImageAlphaPremultipliedLast

    public static CGBitmapInfo bitmapInfo(boolean withAlpha) {
        return new CGBitmapInfo(withAlpha ? kCGImageAlphaPremultipliedLast : kCGImageAlphaNoneSkipLast);
    }

Please note I put a complete set of constants there for reference; some will not work on iOS and/or in all circumstances.

HTH,
Max
Reply all
Reply to author
Forward
0 new messages