iOS修改图片尺寸和裁剪功能以及 图片上加图片 图片加文字(水印效果)
1.修改图片尺寸
- ( UIImage *)imageWithImageSimple:( UIImage *)image scaledToSize:( CGSize )newSize
{
// Create a graphics image context
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;
}
2.裁剪图片
a.
- ( UIImage *)getImageByCuttingImage:( UIImage *)image Rect:( CGRect )rect{
// 大图 bigImage
// 定义 myImageRect ,截图的区域
CGRect myImageRect = rect;
UIImage * bigImage= image;
CGImageRef imageRef = bigImage. CGImage ;
CGImageRef subImageRef = CGImageCreateWithImageInRect (imageRef, myImageRect);
CGSize size;
size. width = rect. size . width ;
size. height = rect. size . height ;
UIGraphicsBeginImageContext (size);
CGContextRef context = UIGraphicsGetCurrentContext ();
CGContextDrawImage (context, myImageRect, subImageRef);
UIImage * smallImage = [ UIImage imageWithCGImage :subImageRef];
UIGraphicsEndImageContext ();
return smallImage;
}
b.
- (UIImage *)ct_imageFromImage:(UIImage *)image inRect:(CGRect)rect{
//把像 素rect 转化为 点rect(如无转化则按原图像素取部分图片)
CGFloat scale = [UIScreen mainScreen].scale;
CGFloat x= rect.origin.x*scale,y=rect.origin.y*scale,w=rect.size.width*scale,h=rect.size.height*scale;
CGRect dianRect = CGRectMake(x, y, w, h);
//截取部分图片并生成新图片
CGImageRef sourceImageRef = [image CGImage];
CGImageRef newImageRef = CGImageCreateWithImageInRect(sourceImageRef, dianRect);
UIImage *newImage = [UIImage imageWithCGImage:newImageRef scale:[UIScreen mainScreen].scale orientation:UIImageOrientationUp];
return newImage;
}
3.改变图片大小缩放方法
-(UIImage*) OriginImage:(UIImage *)image scaleToSize:(CGSize)size {
UIGraphicsBeginImageContext(size); //size为CGSize类型,即你所需要的图片尺寸
[image drawInRect:CGRectMake(0,0, size.width, size.height)];
UIImage* scaledImage =UIGraphicsGetImageFromCurrentImageContext();
UIGraphicsEndImageContext();
return scaledImage; //返回的就是已经改变的图片
}
-(UIImage *)addImageLogo:(UIImage *)img text:(UIImage *)logo {
//get image width and height
int w = img.size.width;
int h = img.size.height;
int logoWidth = logo.size.width/2;
int logoHeight = logo.size.height/2;
CGColorSpaceRef colorSpace =CGColorSpaceCreateDeviceRGB();
//create a graphic context with CGBitmapContextCreate
CGContextRef context =CGBitmapContextCreate(NULL, w, h,8, 4 * w, colorSpace,kCGImageAlphaPremultipliedFirst);
CGContextDrawImage(context,CGRectMake(0,0, w, h), img.CGImage);//先画出第一张图
CGContextDrawImage(context,CGRectMake(0, h - logoHeight, logoWidth, logoHeight), [logoCGImage]); //再画第二张图
CGImageRef imageMasked =CGBitmapContextCreateImage(context);
CGContextRelease(context);
CGColorSpaceRelease(colorSpace);
return [UIImageimageWithCGImage:imageMasked];
}
- (UIImage *)shuiYinOne:(UIImage *)oldImag{
//开启上下文
//size新图片的大小
//opaque YES不透明 NO透明
UIGraphicsBeginImageContextWithOptions(oldImag.size,NO, 0.0);
[oldImag drawAtPoint:CGPointZero];
NSString *str =self.bubbleView.textView.text;
NSDictionary *dict =@{
NSFontAttributeName :self.bubbleView.textView.font,
NSForegroundColorAttributeName :Color(158,194, 24)
};
[str drawAtPoint:self.bubbleView.centerwithAttributes:dict];
//获取新的图片
UIImage *newImage =UIGraphicsGetImageFromCurrentImageContext();
//关闭上下文
UIGraphicsEndImageContext();
return newImage;
}
iOS修改图片尺寸和裁剪功能以及 图片上加图片 图片加文字(水印效果)相关推荐
- java图片加文字水印_JAVA实现图片的修改,添加文字水印效果
JAVA实现图片的修改,添加文字水印效果,根据文字内容生成图片,下面是具体的代码,以及测试方法: 实现类: package JavaMoImage; import javax.p_w_picpathi ...
- 使用mac电脑预览功能修改图片尺寸以及裁剪
想必很多人拿到美工不专业的图片很不爽,其实我们mac电脑的图片预览功能有点厉害(很多开发2年到3年的人都不知道) 1.双击打开图片 2.操作步骤二后的图片 3.直接使用鼠标任意裁剪吧
- deepnode处理过的图片_这款实用的图片软件,其功能相当于十几款图片处理软件的功能之和...
点击蓝字 关注我们 说起格式工厂,相信很多人都用过或者听说过,这款免费的格式转换软件功能强悍,支持众多格式的转换,让它在网上的知名度非常高.而与它师出同门的图片处理软件"图片工厂" ...
- axios获取图片显示_vue中使用axios post上传头像/图片并实时显示到页面的方法
在前端开发中,为了更好的用户体验,在头像上传时会先将图片显示到页面然后点击保存按钮 完成图片的上传成功 代码部分有参考他人的写法. html代码: 请上传图片 js代码: //实时显示该图片在页面 g ...
- flash图片如何镜像翻转_在canvas上实现元素图片镜像翻转动画效果的方法
这篇文章主要介绍了在canvas上实现元素图片镜像翻转动画效果的方法的相关资料,小编觉得挺不错的,现在分享给大家,也给大家做个参考.一起跟随小编过来看看吧! 一.Canvas图片水平镜像翻转效果预览 ...
- C语言用句柄显示bmp图片,VC编程之VC MFC界面上显示BMP图片
本文主要向大家介绍了VC编程之VC MFC界面上显示BMP图片,通过具体的内容向大家展示,希望对大家学习VC编程有所帮助. 1.通过点击界面浏览按钮选择BMP图像文件. 点击浏览按钮打开文件对话框选择 ...
- iOS 修改image尺寸
在一次平铺展示中,UI给的图尺寸不对,于是我自己修改了图片的尺寸,代码如下: -(UIImage *)imageResize :(UIImage*)img andResizeTo:(CGSize)ne ...
- Vue - 实现图片裁剪功能,并上传到服务器(内置第三方最优秀的裁剪图片组件,上传到服务器功能)干净整洁无 BUG 的示例源码与超详细的注释,兼容任意浏览器
前言 您可以滑动到文章最底部,直接克隆完整示例 Gitee 仓库,与本文教程最终效果一致. 在项目开发中,您难免会遇到图片上传到服务器之前,用户可进行裁剪的需求, 在看了网上大部分教程后,代码都非常乱 ...
- 批量修改图片尺寸(适用于4:3和16:9的图片)
import os from PIL import Imagefilename = os.listdir("Z:/project/python_project/2")#打开文件位置 ...
最新文章
- 以太坊 node data write error_Node之 创建服务器与客户端
- PHP写猜数字,PHP算法之猜数字
- 用火狐录制脚本为空_功能测试——链接测试amp;脚本功能
- 数据和判定(二)------运算符
- Atiflash显卡BIOS、Nvflsh显卡BIOS、显卡BIOS刷新与超频详细说明教程--转载+BYZ修正...
- Web 项目中,MySQL 最新驱动下载、及配置
- 【预测模型】加权移动平均法预测煤炭产值
- CAD制图软件中如何设置CAD打印样式表(CTB)?
- Python并发编程相关及在爬虫实战中的使用
- Java使用Thylemeaf + iText实现html(带图片)转pdf文件
- 如何在Windows 10上修复缩略图问题
- AGA 2019电竞狂欢盛宴开启:为全国校园电竞玩家“圆梦”
- 数学之美—细数 傅里叶变换 原理
- 三大运营商URL欺骗;手机免费上网,测试,教程,服务器
- 【Unity云消散】理论基础:实现边缘光
- php 路由器设置密码,为防蹭网宽带密码修改之后无线路由器设置教程
- 渗透之路 安全工具【第四篇】系统漏洞扫描之启明天镜
- business,firm, company, corporation, enterprise等区别CentOS(Community Enterprise Operating System)想到
- matlab画等势线,求助大牛MATLAB画三维等势面
- laravel 效率与java_laravel框架与其他框架的详细对比