//
//  UIImage+Customized.m
//  DingDCommunity
//
//  Created by JianjiYuan on 14-3-12.
//  Copyright (c) 2014年 JianjiYuan. All rights reserved.
//

#import "UIImage+Customized.h"

@implementation UIImage (Customized)

- (UIImage *)reSizeImagetoSize:(CGSize)reSize
{
    UIGraphicsBeginImageContext(CGSizeMake(reSize.width, reSize.height));
    [self drawInRect:CGRectMake(0, 0, reSize.width, reSize.height)];
    UIImage *reSizeImage = UIGraphicsGetImageFromCurrentImageContext();
    UIGraphicsEndImageContext();
    return reSizeImage;
}

- (UIImage *)reSizeImagetoFillWidth:(CGSize)imageSize
{
    CGFloat width = imageSize.width;
    CGFloat height = imageSize.height;
    CGSize newSize = CGSizeMake(320*2, 320*2/width*height);
    
    UIGraphicsBeginImageContext(newSize);
    [self drawInRect:CGRectMake(0, 0, newSize.width, newSize.height)];
    UIImage *reSizeImage = UIGraphicsGetImageFromCurrentImageContext();
    UIGraphicsEndImageContext();
    return reSizeImage;
}

+ (UIImage *)imageWithColor:(UIColor *)color
{
    CGRect rect = CGRectMake(0, 0, 1, 1);
    UIGraphicsBeginImageContext(rect.size);
    CGContextRef context = UIGraphicsGetCurrentContext();
    
    CGContextSetFillColorWithColor(context, [color CGColor]);
    CGContextFillRect(context, rect);
    
    UIImage *image = UIGraphicsGetImageFromCurrentImageContext();
    UIGraphicsEndImageContext();
    
    return image;
}

@end
