如何获取图像的原始颜色
How to get the original color of the image
我尝试在 rebootButton 按钮上获取图像的原始颜色
我可以更改颜色..但我想获得我在 Photoshop 中创建的图像的原始颜色
问题是我取不到原色,整张图只取蓝色
我能得到帮助吗?
UIColor* tintColor;
UIButton *rebootButton = [[UIButton buttonWithType:UIButtonTypeRoundedRect] retain];
rebootButton.frame = CGRectMake(self.view.frame.size.width - 250, self.view.frame.size.height / 2 - 80, 60, 60);
[rebootButton setImage:[UIImage imageWithContentsOfFile: reboot3] forState:UIControlStateNormal];
[rebootButton setTitle:@"Reboot" forState:UIControlStateNormal];
[rebootButton addTarget:self action:@selector(reboot) forControlEvents:UIControlEventTouchUpInside];
if(style != 1) {
rebootButton.tintColor = tintColor;
} else {
if(defaultTheme1 == 0) {
[rebootButton setImage:[UIImage imageWithContentsOfFile: reboot1] forState:UIControlStateNormal];
} else if (defaultTheme1 == 1) {
[rebootButton setImage:[UIImage imageWithContentsOfFile: reboot2] forState:UIControlStateNormal];
} else if (defaultTheme1 == 2) {
[rebootButton setImage:[UIImage imageWithContentsOfFile: reboot3] forState:UIControlStateNormal];
}
}
[powerButton centerVertically];
[myView addSubview:powerButton];
// Load preferences using HBPreferences, I could use NSUserDefaults but HBPreferences is fine for now.
static void loadPrefs() {
NSString *kBackgroundColor = @"";
NSString *kTintColor = @"";
[colorPrefs registerDefaults:@{
@"kBackgroundColor": @"#FFFFFF",
@"kTintColor": @"#007AFF"
}];
kTintColor = [colorPrefs objectForKey:@"kTintColor"];
// Set the tint and background colour to a UIColor
tintColor = LCPParseColorString(kTintColor, kTintColor);
backgroundColor = LCPParseColorString(kBackgroundColor, kBackgroundColor);
}
改变
[rebootButton setImage:[UIImage imageWithContentsOfFile: reboot3] forState:UIControlStateNormal];
至
[rebootButton setImage:[[UIImage imageWithContentsOfFile: reboot3] imageWithRenderingMode: UIImageRenderingModeAlwaysOriginal] forState:UIControlStateNormal];
我尝试在 rebootButton 按钮上获取图像的原始颜色 我可以更改颜色..但我想获得我在 Photoshop 中创建的图像的原始颜色
问题是我取不到原色,整张图只取蓝色 我能得到帮助吗?
UIColor* tintColor;
UIButton *rebootButton = [[UIButton buttonWithType:UIButtonTypeRoundedRect] retain];
rebootButton.frame = CGRectMake(self.view.frame.size.width - 250, self.view.frame.size.height / 2 - 80, 60, 60);
[rebootButton setImage:[UIImage imageWithContentsOfFile: reboot3] forState:UIControlStateNormal];
[rebootButton setTitle:@"Reboot" forState:UIControlStateNormal];
[rebootButton addTarget:self action:@selector(reboot) forControlEvents:UIControlEventTouchUpInside];
if(style != 1) {
rebootButton.tintColor = tintColor;
} else {
if(defaultTheme1 == 0) {
[rebootButton setImage:[UIImage imageWithContentsOfFile: reboot1] forState:UIControlStateNormal];
} else if (defaultTheme1 == 1) {
[rebootButton setImage:[UIImage imageWithContentsOfFile: reboot2] forState:UIControlStateNormal];
} else if (defaultTheme1 == 2) {
[rebootButton setImage:[UIImage imageWithContentsOfFile: reboot3] forState:UIControlStateNormal];
}
}
[powerButton centerVertically];
[myView addSubview:powerButton];
// Load preferences using HBPreferences, I could use NSUserDefaults but HBPreferences is fine for now.
static void loadPrefs() {
NSString *kBackgroundColor = @"";
NSString *kTintColor = @"";
[colorPrefs registerDefaults:@{
@"kBackgroundColor": @"#FFFFFF",
@"kTintColor": @"#007AFF"
}];
kTintColor = [colorPrefs objectForKey:@"kTintColor"];
// Set the tint and background colour to a UIColor
tintColor = LCPParseColorString(kTintColor, kTintColor);
backgroundColor = LCPParseColorString(kBackgroundColor, kBackgroundColor);
}
改变
[rebootButton setImage:[UIImage imageWithContentsOfFile: reboot3] forState:UIControlStateNormal];
至
[rebootButton setImage:[[UIImage imageWithContentsOfFile: reboot3] imageWithRenderingMode: UIImageRenderingModeAlwaysOriginal] forState:UIControlStateNormal];