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

来源:互联网 发布:穿越火线手游淘宝商城 编辑:程序博客网 时间:2024/04/30 12:03

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 = [[UIImageimageNamed:@"left_green_me"]imageWithGradientTintColor:[UIColorredColor]];

    self.img2.image = [[UIImageimageNamed:@"add_cert_me"]imageWithTintColor:[UIColorpurpleColor]];


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 [selfimageWithTintColor:tintColor blendMode:kCGBlendModeDestinationIn];

}


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

{

    return [selfimageWithTintColor: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);

    [tintColorsetFill];

   CGRect bounds = CGRectMake(0,0, self.size.width,self.size.height);

   UIRectFill(bounds);

    

    //Draw the tinted image in context

    [selfdrawInRect:bounds blendMode:blendMode alpha:1.0f];

    

    if (blendMode !=kCGBlendModeDestinationIn) {

        [selfdrawInRect:bounds blendMode:kCGBlendModeDestinationInalpha:1.0f];

    }

    

    UIImage *tintedImage =UIGraphicsGetImageFromCurrentImageContext();

    UIGraphicsEndImageContext();

    

   return tintedImage;

}


@end




android 简述





0 0