如何通过CGImage得到bitmap

在iOS 4.3版本下,Cocoa并未直接提供从CGImage转换为bitmap的API。要获取bitmap,需要创建合适的Context,然后将CGImage绘制到Context,最后从Context提取bitmap数据。这个过程涉及将源图像转换到特定颜色空间,如8位每组件的ARGB色彩空间。详细步骤可参考Apple开发者网站上的QA1509。对于更多不同像素格式的bitmap上下文创建,可以查阅Quartz 2D Programming Guide。
摘要由CSDN通过智能技术生成

在目前(iOS4.3版本已经出来了)cocoa没有提供从CGimage到bitmap的接口,想得到bitmap还得费一番周折。以下是我从苹果开发者网站上找到的一段,可以实现。大体思路为:先创建满足自己要求的Context,再将原图片画到Context上,然后再从Context上得到图片的bitmap数据。

 

原文:http://developer.apple.com/library/ios/#qa/qa1509/_index.html

 

creates a bitmap context with a 8-bits per component ARGB color space, draws the source image to this context, then retrieves the image bits in this color space from the context. Regardless of what the source image format is (CMYK, 24-bit RGB, Grayscale, and so on) it will be converted over to this color space.

 

For more information about creating bitmap contexts for other pixel formats, see the 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值