zoukankan      html  css  js  c++  java
  • iOS图片的裁剪

    - (void)tailoring {

        UIImage *oldImage = [UIImage imageNamed:@"实现准备裁剪的图片.png"];

        

        CGFloat borderW = 2;

        CGFloat imageW = oldImage.size.width + borderW * 2;

        CGFloat imageH = oldImage.size.height + borderW * 2;

        UIGraphicsBeginImageContextWithOptions(CGSizeMake(imageW, imageH), NO, 0.0);

        

        CGContextRef ctx = UIGraphicsGetCurrentContext();

        

        // 圆环

        CGFloat centerX = imageW * 0.5;

        CGFloat centerY = imageH * 0.5;

        CGContextAddArc(ctx, centerX, centerY, centerX, 0, M_PI * 2, 0);

        [[UIColor whiteColor] set];

        CGContextFillPath(ctx);

        

        // 裁剪

        CGFloat radius = oldImage.size.width * 0.5;

        CGContextAddArc(ctx, centerX, centerY, radius, 0, M_PI * 2, 0);

        CGContextClip(ctx);

        

        // 画图

        [oldImage drawInRect:CGRectMake(borderW, borderW, oldImage.size.width, oldImage.size.height)];

        

        UIImage *newImage = UIGraphicsGetImageFromCurrentImageContext();

        UIGraphicsEndImageContext();

        

        NSData *data = UIImagePNGRepresentation(newImage);

        [data writeToFile:@"路径/图片名.png" atomically:YES];

    }

  • 相关阅读:
    dd的用法
    od的用法
    Windows 7安装Oracle 10g的方法
    Ubuntu下的iptux和Windows下的飞秋互传文件
    c++ 12
    c++ 11
    c++ 10
    c++ 09
    c++ 08
    c++ 07
  • 原文地址:https://www.cnblogs.com/iOS771722918/p/4431666.html
Copyright © 2011-2022 走看看