cgbitmapcontextcreate function parameters

Source: Internet
Author: User

cgbitmapcontextcreate function parameters in detail function prototypes:

Cgcontextref Cgbitmapcontextcreate (

void *data,
size_t width,
size_t height,
size_t Bitspercomponent,
size_t Bytesperrow,
Cgcolorspaceref ColorSpace,
Cgbitmapinfo Bitmapinfo

);

Parameters:

Data points to the address of the drawing memory to render. The size of this memory block is at least (bytesperrow*height) bytes

Width bitmap, in pixels

Height bitmap, in pixels

Bitspercomponent the number of bits per component in the in-memory pixels. For example, for 32-bit pixel format and RGB color space, you should set this value to 8.

Bytesperrow bitmap The number of bits per row in memory

ColorSpace The color space used by the bitmap context.

BITMAPINFO Specifies whether the bitmap contains an alpha channel, the relative position of the alpha channel in the pixel, and the pixel component is a string of information such as shaping or floating-point.

Describe:

When you call this function, Quartz creates a bitmap drawing environment, which is the bitmap context. When you draw information to the context, quartz draws the information you want to draw as a bitmap data to the specified memory block. The pixel format of a new bitmap context is determined by three parameters: the number of bits per component, the color space, and the alpha option. The alpha value determines the transparency of the plotted pixel.

[OBJC]View Plaincopy
    1. Implicit conversion from enumeration type ' enum Cgimagealphainfo ' to different enumeration type ' Cgbitmapinfo ' (AK A ' enum Cgbitmapinfo ')
    2. When using the Xcode5 SDK IOS7 environment, creating a graphics context for graphical drawing, merging, cropping, special effects processing and so on can not avoid creating bitmaps using the following methods:
    3. Prior to IOS7, it was created using the following methods:
    4. Cg_extern cgcontextref cgbitmapcontextcreate (voidvoid *data, size_t width,
    5. size_t height, size_t bitspercomponent, size_t bytesperrow,
    6. Cgcolorspaceref Space,cgimagealphainfo Bitmapinfo)
    7. Note the last parameter type is the Kcgimagealphapremultipliedlast value in the Cgimagealphainfo enumeration type.  Its integer value is 1.
    8. typedef cf_enum (UINT32_t, cgimagealphainfo)
    9. {
    10. Kcgimagealphanone,/ * For example, RGB. * /
    11. Kcgimagealphapremultipliedlast,/ * For example, premultiplied RGBA * /
    12. Kcgimagealphapremultipliedfirst,/ * For example, premultiplied ARGB * /
    13. Kcgimagealphalast,/ * For example, non-premultiplied RGBA * /
    14. Kcgimagealphafirst,/ * For example, non-premultiplied ARGB * /
    15. Kcgimagealphanoneskiplast,/ * For example, RBGX. * *
    16. Kcgimagealphanoneskipfirst,/ * For example, Xrgb. * *
    17. Kcgimagealphaonly/ * No color data, alpha data only * /
    18. };
    19. However, in iOS7, this last type of participation has changed. Look at the definition:
    20. Cgcontextref cgbitmapcontextcreate (voidvoid *data, size_t width,
    21. size_t height, size_t bitspercomponent, size_t bytesperrow,
    22. Cgcolorspaceref space, Cgbitmapinfo bitmapinfo)
    23. It's obvious that the last parameter is changed from Cgimagealphainfo to Cgbitmapinfo, so look at the definition of this type.
    24. typedef cf_options (UINT32_t, cgbitmapinfo)
    25. {
    26. Kcgbitmapalphainfomask = 0x1F,
    27. Kcgbitmapfloatcomponents = (1 << 8),
    28. Kcgbitmapbyteordermask = 0x7000,
    29. Kcgbitmapbyteorderdefault = (0 << 12),
    30. Kcgbitmapbyteorder16Little = (1 << 12),
    31. Kcgbitmapbyteorder32Little = (2 << 12),
    32. Kcgbitmapbyteorder16Big = (3 << 12),
    33. Kcgbitmapbyteorder32Big = (4 << 12)
    34. } cf_enum_available (10_4, 2_0);
    35. No enumeration value of 1 was found from beginning to end . Therefore, the following warning will appear when using:
    36. Implicit conversion from enumeration type ' enum Cgimagealphainfo ' to different enumeration type ' Cgbitmapinfo ' (AK A ' enum Cgbitmapinfo ')
    37. The meaning is obvious, however, the type mismatch is illegal.
    38. Here's how to fix this:
    39. The first method, define a macro:
    40. #if __iphone_os_version_max_allowed > __iphone_6_1
    41. #define KCGIMAGEALPHAPREMULTIPLIEDLAST (Kcgbitmapbyteorderdefault | kcgimagealphapremultipliedlast)
    42. #else
    43. #define Kcgimagealphapremultipliedlast Kcgimagealphapremultipliedlast
    44. #endif
    45. This will directly map a macro with a value of 1, the original method does not have to change.
    46. 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.
    47. #if __iphone_os_version_max_allowed > __iphone_6_1
    48. int bitmapinfo = Kcgbitmapbyteorderdefault | kcgimagealphapremultipliedlast;
    49. #else
    50. int bitmapinfo = Kcgimagealphapremultipliedlast;
    51. #endif
    52. Cgcontextref context = cgbitmapcontextcreate (nil, cgcontexwith*2, 290. 0*2, 8, 4  *cgcontexwith*2, ColorSpace, bitmapinfo);
    53. 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.
    54. Reprinted from: http://HI.BAIDU.COM/YUNHUAIKONG/ITEM/0FE2CCCA5F041C7289AD9EAC

cgbitmapcontextcreate function parameters

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.