您的位置:首页 > 编程语言

缩放图片代码

2016-05-26 15:09 260 查看
  - ( UIImage *)imageWithImageSimple:( UIImage *)image scaledToSize:( CGSize )newSize{

        

        // Create a graphics image context

       

        // 创建一个bitmap的context

        // 并把它设置成为当前正在使用的context

        //Determine whether the screen is retina

        if([[UIScreen mainScreen] scale] ==
3.0){

            UIGraphicsBeginImageContextWithOptions(newSize,
NO, 3.0);

        }else
if ([[UIScreen mainScreen] scale] ==
2.0){

            UIGraphicsBeginImageContextWithOptions(newSize,
NO, 2.0);

        }else{

            UIGraphicsBeginImageContext(newSize);

        }

        

        

        //    UIGraphicsBeginImageContext (newSize);

        

        // Tell the old image to draw in this new context, with the desired

        

        // new size

        

        [image drawInRect : CGRectMake ( 0 ,
0 ,newSize. width ,newSize. height )];

        

        // Get the new image from the context

        

        UIImage * newImage = UIGraphicsGetImageFromCurrentImageContext ();

        

        // End the context

        

        UIGraphicsEndImageContext ();

        

        // Return the new image.

        return newImage;

    }

    

    
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: