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

     

     

  • 相关阅读:
    最受欢迎的北大通选课导读·1[精品]
    社会保险,
    养老金的计算,
    毫秒 后的一个计算,
    返回格式 的数据结构再次改造,
    阶段状态池子,
    生活,-摘
    融合,
    tableview 也可以实现这个效果,
    字体大小 一致起来,
  • 原文地址:https://www.cnblogs.com/yuyu-2012/p/4977855.html
Copyright © 2011-2022 走看看