objective-c - 透明度 iOS

标签 objective-c ios xcode

我有一张用 iOS 设备拍摄的图像,其中包含几行文字和一点背景颜色(红色)。我希望图像只向用户显示单词(他们将做类似的事情)。我无法以任何方式使用 UIImageView,因此简单地获取图像并将其放在背景上是行不通的。

所以我想知道是否有人可以告诉我以下哪种方法会给我最好的结果,如果可能的话,并且例子会很好。我在下面发布了我尝试做的但运气不佳的代码(选项 2)。

  1. 将背景设置为白色,以便仅显示文字
  2. 从图像中删除红色

提前致谢

 UIImage *image = [UIImage imageNamed:@"pic1.jpg"];

const float colorMasking[6] = {0.0, 0.0, 0.0, 0.0, 0.0, 0.0};
image = [UIImage imageWithCGImage: CGImageCreateWithMaskingColors(image.CGImage, colorMasking)];

最佳答案

UIImage *image = [UIImage imageNamed:@"image1.jpg"];
UIImage *inputImage = [UIImage imageWithData:UIImageJPEGRepresentation(image, 1.0)];

const float colorMasking[6] = {225.0, 255.0, 225.0, 255.0, 225.0, 255.0};
CGImageRef imageRef = CGImageCreateWithMaskingColors(inputImage.CGImage, colorMasking);

UIImage *img2 = [UIImage imageWithCGImage:imageRef];

我已经从图像背景中删除了浅灰色。RGB 的颜色范围在 225 到 255 之间。现在它看起来是透明的。

关于objective-c - 透明度 iOS,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13115524/

相关文章:

iphone - 显示问题的MKA注释

iphone - 在没有支持变量的情况下在 Xcode 调试器中查看合成属性的值

xcode - iOS 模拟器 : How can I see the background apps?

ios - 每次 Plist 文件都会被覆盖

ios - 从 Parse.com 将 Logo 图像加载到 UIImage

ios - 从静态子项目访问委托(delegate)

xcode - OS X 在 swift 中从 xib 添加 subview

iphone - 无法加载从 Nib 引用的 ""图像

ios - 未使用 iBeacon Simulator 调用 CLLocationManager 委托(delegate)方法

iphone - 找到多个名为 'tag' 的方法