相关疑难解决方法(0)

从UIColor预设中获取RGB值

我的应用程序我将RGB颜色值传递给服务器.我的应用程序使用UIColor预定义值,如[UIColor grayColor],[UIColor redColor].我知道我可以使用以下代码:

const CGFloat *c = CGColorGetComponents(color.CGColor)
Run Code Online (Sandbox Code Playgroud)

但是,仅适用于RBG色彩空间中的颜色,[UIColor grayColor]不是.

有没有办法获得非RBG颜色的RGB值?

谢谢!

iphone objective-c uicolor cgcolorspace

19
推荐指数
2
解决办法
2万
查看次数

iOS颜色在UIImage中透明

如何清除UIImage的洋红色部分并使其透明?

我已经浏览了很多答案和SO上的链接,没有任何作用(例如,如何在UIImage上使一种颜色透明?答案1删除除红色之外的所有内容,答案2显然不起作用,因为为什么CGImageCreateWithMaskingColors()返回nil in这种情况?).

更新:

如果我使用CGImageCreateWithMaskingColors与UIImage我得到一个零值.如果我删除alpha通道(我将图像表示为JPEG并将其读回),CGImageCreateWithMaskingColors将返回涂有黑色背景的图像.

Update2,代码:

返回零:

const float colorMasking[6] = {222, 255, 222, 255, 222, 255};
CGImageRef imageRef = CGImageCreateWithMaskingColors(anchorWithMask.CGImage, colorMasking);

NSLog(@"image ref %@", imageRef);
// this is going to return a nil imgref.

UIImage *image = [UIImage imageWithCGImage:imageRef];
Run Code Online (Sandbox Code Playgroud)

返回带有黑色背景的图像(这是正常的,因为没有alpha通道):

UIImage *inputImage = [UIImage imageWithData:UIImageJPEGRepresentation(anchorWithMask, 1.0)];

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

NSLog(@"image ref %@", imageRef);
// imgref is NOT nil.

UIImage *image = [UIImage imageWithCGImage:imageRef]; …
Run Code Online (Sandbox Code Playgroud)

uiimage ios

9
推荐指数
1
解决办法
2万
查看次数

如何将图像中的特定颜色更改为其他颜色

我有一个 UIView,它的图层内容是图像。

let image = UIImage(names: "myImage")
layer.contents = image.CGImage
Run Code Online (Sandbox Code Playgroud)

该图像有几种颜色。

有没有办法将特定颜色更改为我选择的任何其他颜色?

我找到了更改图像中所有颜色的答案,但没有找到特定颜色的答案。

回答

uikit uiimage swift

2
推荐指数
1
解决办法
2857
查看次数

将 PNG 图像的背景从白色更改为透明

我有一个 PNG 图像文件,我正在使用 UIImageView 在视图中显示图像。我想将图像中的白色更改为透明。

注意:我的父视图颜色可以是不同的颜色。(不只是白色)

这是我的代码:

UIImageView* oriImageView = [[UIImageView alloc]initWithFrame:originalFrame];
UIImage* oriImage = [UIImage imageNamed:@"tap.png"];
oriImageView.layer.opacity = 0.5f;
oriImageView.backgroundColor = [UIColor clearColor];
oriImageView.opaque = NO;
oriImageView.tintColor = [UIColor clearColor];
oriImageView.image = oriImage;
[self.view addSubview:oriImageView];
Run Code Online (Sandbox Code Playgroud)

我尝试了以下不同的选项,但没有成功。

oriImageView.backgroundColor = [UIColor clearColor];
oriImageView.opaque = NO;
oriImageView.tintColor = [UIColor clearColor];
Run Code Online (Sandbox Code Playgroud)

在此输入图像描述

我的iOS模拟器截图: 在此输入图像描述

uiimageview ios

1
推荐指数
1
解决办法
1826
查看次数

标签 统计

ios ×2

uiimage ×2

cgcolorspace ×1

iphone ×1

objective-c ×1

swift ×1

uicolor ×1

uiimageview ×1

uikit ×1