zoukankan      html  css  js  c++  java
  • 改变图片颜色(灰色显示)

    UIImage+grayColor.h
    
    #import <UIKit/UIKit.h>
    
    @interface UIImage (grayColor)
    
    + (UIImage *)grayImage:(UIImage *)sourceImage;
    
    @end
    
    UIImage+grayColor.m
    
    #import "UIImage+grayColor.h"
    
    @implementation UIImage (grayColor)
    
    + (UIImage *)grayImage:(UIImage *)sourceImage
    {
        int bitmapInfo = kCGImageAlphaNone;
        int width = sourceImage.size.width;
        int height = sourceImage.size.height;
        CGColorSpaceRef colorSpace = CGColorSpaceCreateDeviceGray();
        CGContextRef context = CGBitmapContextCreate (nil,
                                                      width,
                                                      height,
                                                      8,      // bits per component
                                                      0,
                                                      colorSpace,
                                                      bitmapInfo);
        CGColorSpaceRelease(colorSpace);
        if (context == NULL) {
            return nil;
        }
        CGContextDrawImage(context,
                           CGRectMake(0, 0, width, height), sourceImage.CGImage);
        UIImage *grayImage = [UIImage imageWithCGImage:CGBitmapContextCreateImage(context)];
        CGContextRelease(context);
        return grayImage;
    }
    
    @end
    
    // 使用
     UIImageView *imageView = [[UIImageView alloc]initWithFrame:CGRectMake(0, 0, 320, self.view.frame.size.height)];
     [imageView setImage:[UIImage grayImage:[UIImage imageNamed:@"dark.jpg"]]];
     [self.view addSubview:imageView];
  • 相关阅读:
    matrix_last_acm_4
    matrix_last_acm_3
    matrix_last_acm_2
    matrix_last_acm_1
    2015亚洲区北京站网络赛
    poj 1062 昂贵的聘礼 最短路
    2-SAT !!
    hdu 4925
    hdu 4927 Java大数
    poj3687 拓扑排序 还没怎么搞明白 回头再想想
  • 原文地址:https://www.cnblogs.com/joesen/p/3540125.html
Copyright © 2011-2022 走看看