Cgbitmapcontextcreate changes under the iOS7

Source: Internet
Author: User

Kcgimagealphapremultipliedfirst and Kcgimagealphafirst when using the XCODE5 SDK iOS7 environment, creating a graphical context for drawing, merging, cropping, special effects processing, and so on can not avoid creating bitmaps using the following methods:

Before IOS7, it was created using the following method:

Cg_extern cgcontextref cgbitmapcontextcreate (void *data, size_t width,

size_t height, size_t bitspercomponent, size_t Bytesperrow,

Cgcolorspaceref Space,cgimagealphainfo Bitmapinfo)

Note the last parameter type is the Kcgimagealphapremultipliedlast value in the Cgimagealphainfo enumeration type. Its integer value is 1.

typedef cf_enum (uint32_t, Cgimagealphainfo)

{

Kcgimagealphanone,/* For example, RGB. */

Kcgimagealphapremultipliedlast,/* For example, premultiplied RGBA */

Kcgimagealphapremultipliedfirst,/* For example, premultiplied ARGB */

Kcgimagealphalast,/* For example, non-premultiplied RGBA */

Kcgimagealphafirst,/* For example, non-premultiplied ARGB */

Kcgimagealphanoneskiplast,/* For example, RBGX. */

Kcgimagealphanoneskipfirst,/* For example, Xrgb. */

Kcgimagealphaonly/* No color data, alpha data only */

};

However, in the iOS7 version, this last type of participation has changed. Look at the definition:

Cgcontextref cgbitmapcontextcreate (void *data, size_t width,

size_t height, size_t bitspercomponent, size_t Bytesperrow,

Cgcolorspaceref space, Cgbitmapinfo bitmapinfo)

It's obvious that the last parameter is changed from Cgimagealphainfo to Cgbitmapinfo, so look at the definition of this type.

typedef cf_options (uint32_t, Cgbitmapinfo)

{

Kcgbitmapalphainfomask = 0x1F,

Kcgbitmapfloatcomponents = (1 << 8),

Kcgbitmapbyteordermask = 0x7000,

Kcgbitmapbyteorderdefault = (0 << 12),

Kcgbitmapbyteorder16little = (1 << 12),

Kcgbitmapbyteorder32little = (2 << 12),

Kcgbitmapbyteorder16big = (3 << 12),

Kcgbitmapbyteorder32big = (4 << 12)

} cf_enum_available (10_4, 2_0);

No enumeration value of 1 was found from beginning to end. Therefore, the following warning will appear when using:

Implicit conversion from enumeration type ' enum Cgimagealphainfo ' to different enumeration type ' Cgbitmapinfo ' (aka ' enum Cgbitmapinfo ')

The meaning is obvious, however, the type mismatch is illegal.

Here's how to fix this:

The first method, define a macro:

#if __iphone_os_version_max_allowed > __iphone_6_1

#define KCGIMAGEALPHAPREMULTIPLIEDLAST (Kcgbitmapbyteorderdefault | kcgimagealphapremultipliedlast)

#else

#define Kcgimagealphapremultipliedlast Kcgimagealphapremultipliedlast

#endif

This will directly map a macro with a value of 1, the original method does not have to change.

The second method: the principle is the same as the first one, the purpose is to produce a value of 1, directly modify the code.

#if __iphone_os_version_max_allowed > __iphone_6_1

int bitmapinfo = Kcgbitmapbyteorderdefault | Kcgimagealphapremultipliedlast;

#else

int bitmapinfo = Kcgimagealphapremultipliedlast;

#endif

Cgcontextref context = Cgbitmapcontextcreate (nil, cgcontexwith*2, 290.0*2, 8, 4*cgcontexwith*2, ColorSpace, BitmapInfo) ;

In fact, all the way to make the value here is 1, type matching. You can also direct 1, without the hassle of various write code. You can also type-cast directly, this you casually. Just everyone's habits are not the same, so, how to solve, their own reference decision.

Cgbitmapcontextcreate changes under iOS7

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.