码迷,mamicode.com
首页 > 移动开发 > 详细

IOS 图片失真

时间:2015-11-19 16:20:27      阅读:151      评论:0      收藏:0      [点我收藏+]

标签:

      1. 问题:图片过小,需要放大到合适尺寸

         技术分享

        //对图片进行压缩

        defaultStatusImg1 = [self scaleImage:defaultStatusImg1 toScale:1.5f];

        

       2. 问题:图片失真

       技术分享

        //图片失真

        defaultStatusImg1 =  [UIImage_Extend imageWithColor:[UIColor clearColor] withImage:defaultStatusImg1 withSize:itemRect.size withOffsetPoint:CGPointMake(34.f,5.f)];//offsetPoint可以使图片和文字对齐

 

 

 

- (UIImage *)scaleImage:(UIImage *)image toScale:(float)scaleSize

 

{

    

    UIGraphicsBeginImageContext(CGSizeMake(image.size.width * scaleSize, image.size.height * scaleSize));

    

    [image drawInRect:CGRectMake(0, 0, image.size.width * scaleSize, image.size.height * scaleSize)];

    UIImage *scaledImage = UIGraphicsGetImageFromCurrentImageContext();

    UIGraphicsEndImageContext();

    

    return scaledImage;   

}

 

前提:

1.导入framework-libuiframework.a

2.创建UIImage_Extend:

//  UIImage+Extend.h

#import <Foundation/Foundation.h>

 

@interface UIImage_Extend : NSObject

 

+(UIImage*)imageCroppedToFitSize:(CGSize)size withFileName:(NSString*)fileName;

+(UIImage *)imageCroppedToFitSize:(CGSize)size withData:(UIImage*)srcData;

 

+(UIImage*)imageCroppedToFitSizeII:(CGSize)size withData:(UIImage *)srcData;

+(UIImage*)imageCroppedToFitSizeII:(CGSize)size withFileName:(NSString*)fileName;

 

+(UIImage*)imageScaleToFitSize:(CGSize)size withFileName:(NSString*)fileName;

+(UIImage*)imageScaleToFitSize:(CGSize)size withData:(UIImage*)srcData;

 

+(UIImage *)makeRoundCornerImage:(UIImage*)img :(int) cornerWidth :(int) cornerHeight;

+(UIImage *)imageWithColor:(UIColor *)color;

+(UIImage *)imageWithColor:(UIColor *)color  withImage:(UIImage*)contentImage withSize:(CGSize)size;

+(UIImage *)imageWithColor:(UIColor *)color  withImage:(UIImage*)contentImage withSize:(CGSize)size withOffsetPoint: (CGPoint)point;

@end

 

 

IOS 图片失真

标签:

原文地址:http://www.cnblogs.com/yuyu-2012/p/4977855.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!