透明iOS [英] Transparency iOS
问题描述
我有一张用我的 iOS 设备拍摄的图像,其中包含几行文字和一点背景颜色(红色).我希望图像只向用户显示单词(他们会做类似的事情).我不能以任何方式使用 UIImageView,所以简单地拍摄图像并将其放在背景上是行不通的.
I have an image that I took with my iOS device that contains a few lines of words and little bit of background colour (red). I want the image to only display the words to the user (they will be doing something similar). I cannot use an UIImageView in any way so simply taking the image and putting it on the background will not work.
所以我想知道是否有人可以告诉我以下哪种方法可以给我最好的结果,如果它们可能的话并且示例会很好.我在下面发布了代码,说明我在运气不佳的情况下尝试做的事情(选项 2).
So I was wondering if someone could tell me which of the following methods would give me the best results, if they are possible and example would be nice. I have posted code below of what I have tried to do with little luck (option 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 之间.现在它看起来是透明的.
I have removed the light gray color from the background of my image.The range of color is given between 225 and 255 for RGB. Now it appears transparent.
这篇关于透明iOS的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!