如何创建仅Alpha位图上下文 [英] How do I create an alpha only bitmap context

查看:115
本文介绍了如何创建仅Alpha位图上下文的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

Apple技术说明 QA1037 说:创建纯Alpha位图上下文只需为colorspace参数传递NULL。

Apple tech note QA1037 says "To create an alpha-only bitmap context simply pass NULL for the colorspace parameter."

但是,我不确定 bitmapInfo 参数传递什么。

However, I am not sure what to pass for the bitmapInfo parameter.

我正在尝试使用kCGImageAlphaOnly这样的事情:

I was trying something like this, with kCGImageAlphaOnly:

CGContextRef ctx = CGBitmapContextCreate(NULL, scaledSize.width, scaledSize.height, 8, scaledSize.width, NULL, kCGImageAlphaOnly);

但这给我一个关于枚举错误的警告。我应该放在哪里呢?

But this gives me an warning about the enum being wrong. What should I put there instead?

推荐答案

文档清楚地表明您可以使用 CGImageAlphaInfo 即使参数已根据需要定义,也来自 CGBitmapInfo 枚举值。

The docs clearly state you can use values from the CGImageAlphaInfo even though the parameter is defined as needed a value from the CGBitmapInfo enum.

一个解决方案是将值强制转换为

One solution would be to cast the value:

(CGBitmapInfo)kCGImageAlphaOnly

这将使编译器感到满意。

That will make the compiler happy.

这篇关于如何创建仅Alpha位图上下文的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆