您的位置:首页 > 移动开发 > Android开发

ios客户端学习-ios及android改变图片颜色的方法

2016-01-12 17:50 627 查看

iOS:

学习资料链接:http://www.onevcat.com/2013/04/using-blending-in-ios/

下载地址:https://github.com/onevcat/VVImageTint

android:

转载地址:http://www.360doc.com/content/14/0818/05/4587493_402721688.shtml

iOS 简述

使用方法
2.在类里面调用如下

#import "UIImage+Tint.h"

self.img.image = [[UIImage
imageNamed:@"left_green_me"]
imageWithGradientTintColor:[UIColor
redColor]];

    self.img2.image
= [[UIImage
imageNamed:@"add_cert_me"]imageWithTintColor:[UIColor
purpleColor]];

1.创建.h和.m文件



.h

#import <UIKit/UIKit.h>

@interface UIImage (Tint)

- (UIImage *) imageWithTintColor:(UIColor *)tintColor;
- (UIImage *) imageWithGradientTintColor:(UIColor *)tintColor;

@end

。m

#import "UIImage+Tint.h"

@implementation UIImage (Tint)
- (UIImage *) imageWithTintColor:(UIColor *)tintColor
{

    return [self
imageWithTintColor:tintColor blendMode:kCGBlendModeDestinationIn];
}

- (UIImage *) imageWithGradientTintColor:(UIColor *)tintColor
{

    return [self
imageWithTintColor:tintColor blendMode:kCGBlendModeOverlay];
}

- (UIImage *) imageWithTintColor:(UIColor *)tintColor blendMode:(CGBlendMode)blendMode
{

    //We want to keep alpha, set opaque to NO; Use 0.0f for scale to use the scale factor of the device’s main screen.

    UIGraphicsBeginImageContextWithOptions(self.size,
NO,
0.0f);
    [tintColor
setFill];
   
CGRect bounds = CGRectMake(0,
0, self.size.width,
self.size.height);
   
UIRectFill(bounds);

    

    //Draw the tinted image in context
    [self
drawInRect:bounds
blendMode:blendMode alpha:1.0f];

    

    if (blendMode !=
kCGBlendModeDestinationIn) {

        [self
drawInRect:bounds blendMode:kCGBlendModeDestinationIn
alpha:1.0f];
    }

    

    UIImage *tintedImage =
UIGraphicsGetImageFromCurrentImageContext();

    UIGraphicsEndImageContext();

    
   
return tintedImage;
}

@end

android 简述

内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: