zoukankan      html  css  js  c++  java
  • IOS 图片失真

          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

     

     

  • 相关阅读:
    2016/01/13开始学习git:分支管理:创建、合并、删除分支
    2016/01/13开始学习git:远程仓库
    2016/01/13开始学习git:删除文件
    2016/01/13开始学习git:管理修改、撤销修改
    2016/01/12开始学习git:版本如何回退
    2016/01/11开始学习git:查看仓库状态和修改文件
    2016/01/11开始学习git:创建版本库后,add和commit
    2016/01/10开始学习git:安装msysgit
    Django web框架开发基础-django实现留言板功能
    Django web框架开发基础-01
  • 原文地址:https://www.cnblogs.com/yuyu-2012/p/4977855.html
Copyright © 2011-2022 走看看