ios 将图片变成圆形

#pragma mark - 将图片转换成圆形

-(UIImage*) circleImage:(UIImage*) image withParam:(CGFloat) inset {

UIGraphicsBeginImageContext(image.size);

CGContextRef context = UIGraphicsGetCurrentContext();

CGContextSetLineWidth(context, 2);

CGContextSetStrokeColorWithColor(context, [UIColor whiteColor].CGColor);

CGRect rect = CGRectMake(inset, inset, image.size.width - inset * 2.0f, image.size.height - inset * 2.0f);

CGContextAddEllipseInRect(context, rect);

CGContextClip(context);

[image drawInRect:rect];

CGContextAddEllipseInRect(context, rect);

CGContextStrokePath(context);

UIImage *newimg = UIGraphicsGetImageFromCurrentImageContext();

UIGraphicsEndImageContext();

return newimg;

}

上面代码注意 如果裁剪后没有使用 CGContextAddEllipseInRect(context, rect);
CGContextStrokePath(context); 这条代码 就会引起背景为白色时看不出来任务效果。
这里是椭圆操作

时间: 2024-08-11 00:48:30

ios 将图片变成圆形的相关文章

IOS把图片做成圆形效果

利用CAShapeLayer可以制作出任意的几何图形,把它作为UIImageView的遮罩,达到把图片做成圆形效果. imgView = [[UIImageView alloc]initWithFrame:CGRectMake(10, 35, 80, 80)]; imgView.image = [UIImage imageNamed:@"ma.jpg"]; UIBezierPath* path = [UIBezierPath bezierPathWithArcCenter:CGPoin

iOS设置圆角及圆形图片

方方正正的样式往往会显得很生硬,而圆角的样式会让人产生别样的亲切感,现在越来越多地用到圆角,诸如用户头像之类的图片也大都用圆形来显示,本文就介绍如何设置按钮.文本框的圆角以及制作圆形的图片. 先来看看效果图: 如效果图所示,我们制作了一个圆形的头像,一个完全半圆的圆角按钮,一个小圆角的按钮,以及一个带边框且边框为圆角的label. 大概思路如下: View都有一个layer的属性,我们正是通过layer的一些设置来达到圆角的目的,因此诸如UIImageView.UIButton.UILabel等

麦子学院ios笔记:IOS把图片缓存到本地的几种方法

把ios的图片缓存到本地的方法有几种?现在来看看学生在麦子学院学习ios开发的笔记中有讲到哪几种方法呢? <code>把图片缓存到本地,在很多场景都会用到,如果是只储存文字信息,那建一个plist文件,或者数据库就能很方便的解决问题,但是如果存图片到沙盒就没那么方便了.这里介绍两种保存图片到沙盒的方法. </code> 一.把图片转为base64的字符串存到数据库中或者plist文件中,然后用到的时候再取出来 <code class="hljs" obje

CircleImageManager ——将图片转换为圆形图片的类

package com.kale.utils; import android.content.Context; import android.graphics.Bitmap; import android.graphics.BitmapFactory; import android.graphics.Canvas; import android.graphics.Paint; import android.graphics.PorterDuffXfermode; import android.g

iOS 把图片存到相册中

把图片存到相册中 -(void)savaPicAction{ UIImageWriteToSavedPhotosAlbum(_imageView.image, nil, nil, nil); UIAlertView * alert = [[UIAlertView alloc] initWithTitle:nil message:@"保存成功" delegate:self cancelButtonTitle:nil otherButtonTitles:@"确定", n

iOS多图片下载

iOS多图片下载.在cell里面下载图片.做了缓存优化. (app.icon是图片地址) // 先从内存缓存中取出图片 UIImage *image = self.images[app.icon]; if (image) { // 内存中有图片 cell.imageView.image = image; } else { // 内存中没有图片 // 获得Library/Caches文件夹 NSString *cachesPath = [NSSearchPathForDirectoriesInDo

IOS 给图片添加水印(文字)

有时候上传图片要加唯一标识,简单的就是添加一个水印.这里水印我们讲文字,可以是当前系统时间.坐标.地理位置等 原理就是把一个字符串写到图片上,并且字(font)的大小由图片大小控制. 以下是封装好的一个类方法: //NavView.m + (UIImage *) addText:(UIImage *)img text:(NSString *)mark { int w = img.size.width; int h = img.size.height; UIGraphicsBeginImageCo

android开发步步为营之58:给图片绘制圆形气泡背景效果

最近在开发项目的时候,有一个需求,需要给应用图标绘制圆形气泡背景,有了彩色气泡这样显得漂亮一点,气泡的颜色是应用图标的颜色均值,先看看效果,然后,我再给出demo. demo应用图标是这样的: 添加气泡背景后是这样的: 仔细看圆形背景颜色是图标颜色的均值. 好的,下面我们来完成这个demo. 第一步.编写页面activity_drawcycle.xml <?xml version="1.0" encoding="utf-8"?> <LinearLa

iOS:获取图片Alpha图片

-(void)createImages { // Load the alpha image, which is just the same Ship.png image used in the clipping demo NSString *imagePath = [[NSBundle mainBundle] pathForResource:@"Ship.png" ofType:nil]; UIImage *img = [UIImage imageWithContentsOfFile: