- c - 在位数组中找到第一个零
- linux - Unix 显示有关匹配两种模式之一的文件的信息
- 正则表达式替换多个文件
- linux - 隐藏来自 xtrace 的命令
我对图像处理很陌生。我必须在我的 iPhone 应用程序项目中实现色调效果。因此,我需要更改 UIImage
的色调。请为此提供任何示例代码或教程链接。
提前致谢
最佳答案
首先,您需要决定是将图像设为固定色调,还是旋转现有色调。两者的示例如下所示。
可以使用标准绘图工具修复色调 - 只需确保将混合模式设置为 kCGBlendModeHue
,然后使用适当的色调进行绘制。这是源自 Nitish 的解决方案,尽管我发现使 saturation
小于 1.0
会产生不一致的结果。此方法确实允许改变 alpha,但对于 100% 以外的真实饱和度,您可能需要第二轮绘图。
- (UIImage*) imageWithImage:(UIImage*) source fixedHue:(CGFloat) hue alpha:(CGFloat) alpha;
// Note: the hue input ranges from 0.0 to 1.0, both red. Values outside this range will be clamped to 0.0 or 1.0.
{
// Find the image dimensions.
CGSize imageSize = [source size];
CGRect imageExtent = CGRectMake(0,0,imageSize.width,imageSize.height);
// Create a context containing the image.
UIGraphicsBeginImageContext(imageSize);
CGContextRef context = UIGraphicsGetCurrentContext();
[source drawAtPoint:CGPointMake(0,0)];
// Draw the hue on top of the image.
CGContextSetBlendMode(context, kCGBlendModeHue);
[[UIColor colorWithHue:hue saturation:1.0 brightness:1 alpha:alpha] set];
UIBezierPath *imagePath = [UIBezierPath bezierPathWithRect:imageExtent];
[imagePath fill];
// Retrieve the new image.
UIImage *result = UIGraphicsGetImageFromCurrentImageContext();
UIGraphicsEndImageContext();
return result;
}
要旋转色调,您需要 Core Image 滤镜。下面的代码将 UIImage 转换为 CIImage,然后将结果转换回 UIImage 进行显示。根据图像的来源,您可以避免其中一个或两个步骤。
方便的是,Core Image Programming Guide: Using Core Image Filters 中的第一个示例使用 CIHueAdjust 过滤器。
// #import <CoreImage/CoreImage.h>
// Partially from https://developer.apple.com/library/mac/#documentation/graphicsimaging/conceptual/CoreImaging/ci_tasks/ci_tasks.html
- (UIImage*) imageWithImage:(UIImage*) source rotatedByHue:(CGFloat) deltaHueRadians;
{
// Create a Core Image version of the image.
CIImage *sourceCore = [CIImage imageWithCGImage:[source CGImage]];
// Apply a CIHueAdjust filter
CIFilter *hueAdjust = [CIFilter filterWithName:@"CIHueAdjust"];
[hueAdjust setDefaults];
[hueAdjust setValue: sourceCore forKey: @"inputImage"];
[hueAdjust setValue: [NSNumber numberWithFloat: deltaHueRadians] forKey: @"inputAngle"];
CIImage *resultCore = [hueAdjust valueForKey: @"outputImage"];
// Convert the filter output back into a UIImage.
// This section from http://stackoverflow.com/a/7797578/1318452
CIContext *context = [CIContext contextWithOptions:nil];
CGImageRef resultRef = [context createCGImage:resultCore fromRect:[resultCore extent]];
UIImage *result = [UIImage imageWithCGImage:resultRef];
CGImageRelease(resultRef);
return result;
}
关于iphone - 如何以编程方式更改 UIImage 的色调?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11555071/
我想将一些颜色值从众所周知的 HSL 转换为鲜为人知的 HSLum 怎么做? hsl(0, 1.0, 0.5) - rgb red is hslum(0, 1.0., 0.54) hsl(120,
在 xml 中为 ImageView 设置色调时,我收到一条警告,显示:- 必须使用 app:tint 而不是 android:tint 为什么我应该使用 app:tint? 最佳答案 因为有一些问题
如果我有一个 alpha 整数和三个用于色调、饱和度和亮度的 float ,我如何使用一种方法以最紧凑的方式将它们转换为一个 argb 值? 编辑:我知道我可以使用 HSBtoRGB,我已经通读了 j
尝试在 firemonkey 中实现类似于此的环形颜色选择器:http://dph.am/iDropper/ 我认为可以使用在笔划上具有多点渐变的 TCircle 来完成。根据我的实验和研究,渐变只能
我在 Hadoop 2.6.2 集群中使用 Hue 3.9。这些计算机都有 Ubuntu 14.04。我能够成功安装 Hue,但从 Web UI 查看 hue 时确实出现了一些错误。我试图一次解决这些
有没有一种方法可以使用 jQ 或某些插件对图像进行着色(应用色调)?谢谢 最佳答案 我能想到的最简单的方法是在图像上覆盖一个半透明的 div。 一个小例子: HTML CSS .overlay
类似于this previous question ,我想将任意颜色的色调应用于任意图像(UIImageView)。然而,我希望色调在 N 秒的时间内逐渐消失,以产生“脉冲”效果。我将每 M 秒触发一
是否有任何命令来检查Hadoop中当前正在运行多少个色调 session ,以及是否有任何方法可以查看已随着年龄运行的 session ? 最佳答案 一个可以帮助解决这个问题的吉拉是HUE-2288
我是 seaborn 的新手,我有这个数据集,想创建一个这样的图表,但要使用 seaborn。 这是我的数据: max_depth = [ 3, 3, 3, 3, 3, 5, 5, 5,
我是 seaborn 的新手,我有这个数据集,想创建一个这样的图表,但要使用 seaborn。 这是我的数据: max_depth = [ 3, 3, 3, 3, 3, 5, 5, 5,
如何使用 Stylus 更改十六进制颜色值的色调和增加饱和度? 最佳答案 Stylus 实际上内置了这些功能。基于文档 hue , saturation : 以下应该有效: 色调(#00c, 90de
我正在尝试创建一个应用程序,允许我通过调整上述每个字段的搜索栏来调整图像的色调、饱和度、亮度、对比度和清晰度。喜欢 http://ronbigelow.com/articles/workflow_ba
我为此问题创建了一个示例数据集 import pandas as pd from pandas import DataFrame import seaborn as sns import numpy
(HI) 我不是比色学方面的专家,但我想知道如何实现基于主色生成随机颜色的脚本。 可能是随机的阴影或色调 例如:#f25f9a。 http://www.color-hex.com/color/f25f
我用 TextView 制作了一些复选框和单选按钮,但它们在 Lollipop 之前没有着色。 我的 TextView 扩展 AppCompatCheckedTextView,样式如下: ?
我创建了一个启用了分析的 Solr 仪表板。计数器按钮现在显示,但它是灰色的。 Hue 或 solr 中是否有任何我应该启用的附加标志? 谢谢 我正在使用 Solr 7 + Hue 4 最佳答案 这是
正如标题所说,如何将状态栏图标的颜色更改为深色调而不是默认的白色。 来自 到 最佳答案 要使状态栏图标具有深色而不是默认的白色,请在 styles.xml 中添加以下标记(或者更准确地说是在 valu
刚刚在我的 iPhone 3GS 上切换到 iOS 4,我的一些应用程序崩溃了。 我遇到的一个问题是,我有一个带有一些按钮的 UIToolbar,颜色为粉红色,在 3.1.3 操作系统上运行良好。升级
我有一个“位图”类型,其中包含一些随机位图数据。我已经编写了自己的亮度、颜色、饱和度和色调调整,这些调整分别作用于每个位,毫不奇怪,速度非常慢。 在我的研究中,我注意到使用矩阵可以非常快地调整这些。此
假 --> HEX color:
我是一名优秀的程序员,十分优秀!