图片处理view - 成图,
方法一:
-(UIImage *)clipImageFromImage:(UIImage *)orgImage Rect:(CGRect)clipRect{
CGImageRef imageRef = orgImage.CGImage;
CGImageRef subImageRef = CGImageCreateWithImageInRect(imageRef, clipRect);
CGSize size;
size = clipRect.size;
UIGraphicsBeginImageContext(size);
CGContextRef context = UIGraphicsGetCurrentContext();
CGContextDrawImage(context, clipRect, subImageRef);
UIImage* clipImage = [UIImage imageWithCGImage:subImageRef];
CGImageRelease(subImageRef);
UIGraphicsEndImageContext();
return clipImage;
}
self.view.frame = CGRectMake(0, 0, 68, 53);//设置图片的大小
UIImageView *bgImg = [[UIImageView alloc] initWithFrame:CGRectMake(0, 0, 68, 53)];//设置图片的背景图片
bgImg.image = [UIImage imageNamed:@"1.png"];
[self.view addSubview:bgImg];
[bgImg release];
if(lab == nil)
lab = [[UILabel alloc] initWithFrame:CGRectMake(0, 20, 68, 30)];//设置图片上面的文字显示
lab.textAlignment = UITextAlignmentCenter;
lab.textColor = [UIColor blackColor];
lab.backgroundColor = [UIColor clearColor];
lab.text = [[titleArray objectAtIndex:i] objectAtIndex:0];
[self.view addSubview:lab];
UIGraphicsBeginImageContext(self.view.bounds.size);
[self.view.layer renderInContext:UIGraphicsGetCurrentContext()];
UIImage *aImage = UIGraphicsGetImageFromCurrentImageContext();
UIGraphicsEndImageContext();
NSData *imageData = UIImagePNGRepresentation(aImage);
UIImage *img = [UIImage imageWithData:imageData];//生成的图片
方法三:
+ (UIImage *)captureWithView:(UIView *)view
{// 1.开始上下文UIGraphicsBeginImageContextWithOptions(view.frame.size, NO, 0.0);// 2.将view的layer渲染到上下文[view.layer renderInContext:UIGraphicsGetCurrentContext()];// 3.取出图片UIImage *newImage = UIGraphicsGetImageFromCurrentImageContext();// 4.结束上下文UIGraphicsEndImageContext();return newImage;
}
方法四:(生产图片并保存到相册)
- UIImage* layerImage = nil;
- CGSize layerSize = self.contentScrollView.frame.size;
- UIGraphicsBeginImageContextWithOptions(layerSize, NO, 2.0);
- [self.contentScrollView.layer renderInContext:UIGraphicsGetCurrentContext()];
- layerImage = UIGraphicsGetImageFromCurrentImageContext();
- UIGraphicsEndImageContext();
- UIImageWriteToSavedPhotosAlbum(layerImage, nil, nil, nil);
//将image1拼接到image2上
- (UIImage *)addImage:(UIImage *)image1 toImage:(UIImage *)image2
{
@autoreleasepool {
CGSize size;
if (image1.size.width > image2.size.width) {
size = CGSizeMake(image1.size.width, image1.size.height+image2.size.height);
} else {
size = CGSizeMake(image2.size.width, image1.size.height+image2.size.height);
}
UIGraphicsBeginImageContext(size);
// Draw image1
[image1 drawInRect:CGRectMake(image1.size.width > image2.size.width?0:(image2.size.width-image1.size.width)/2, image2.size.height, image1.size.width, image1.size.height)];
// Draw image2
[image2 drawInRect:CGRectMake(image1.size.width > image2.size.width?(image1.size.width-image2.size.width)/2:0, 0, image2.size.width, image2.size.height)];
UIImage *resultingImage = UIGraphicsGetImageFromCurrentImageContext();
UIGraphicsEndImageContext();
return resultingImage;
}
}
//图片缩放
- (UIImage *)convertImage:(UIImage *)origImage scope:(CGFloat)scope
{
UIImage *image = nil;
CGSize size = origImage.size;
if (size.width <= scope && size.height <= scope) {
// do nothing
image = origImage;
} else {
CGFloat length = size.width;
if (size.width < size.height) {
length = size.width;
}
CGFloat f = scope/length;
CGSize newSize = CGSizeMake(size.width*f, size.height*f);
//
UIGraphicsBeginImageContext(newSize);
// Tell the old image to draw in this new context, with the desired
// new size
[origImage drawInRect:CGRectMake(0, 0, newSize.width, newSize.height)];
// Get the new image from the context
image = UIGraphicsGetImageFromCurrentImageContext();
UIGraphicsEndImageContext();
}
return image;
}
//将webView上面的内容转化为图片
- (UIImage *)webContentImage{
CGSize boundsSize = web.bounds.size;
CGFloat boundsWidth = web.bounds.size.width;
CGFloat boundsHeight = web.bounds.size.height;
CGPoint offset = web.scrollView.contentOffset;
[web.scrollView setContentOffset:CGPointMake(0, 0)];
CGFloat contentHeight = web.scrollView.contentSize.height;
NSMutableArray *images = [NSMutableArray array];
while (contentHeight > 0) {
UIGraphicsBeginImageContext(boundsSize);
视图生产界面,图片拼接,缩放处理
[web.layer renderInContext:UIGraphicsGetCurrentContext()];
UIImage *image = UIGraphicsGetImageFromCurrentImageContext();
UIGraphicsEndImageContext();
[images addObject:image];
CGFloat offsetY = web.scrollView.contentOffset.y;
[web.scrollView setContentOffset:CGPointMake(0, offsetY + boundsHeight)];
contentHeight -= boundsHeight;
}
[web.scrollView setContentOffset:offset];
UIGraphicsBeginImageContext(web.scrollView.contentSize);
[images enumerateObjectsUsingBlock:^(UIImage *image, NSUInteger idx, BOOL *stop) {
[image drawInRect:CGRectMake(0, boundsHeight * idx, boundsWidth, boundsHeight)];
}];
UIImage *fullImage = UIGraphicsGetImageFromCurrentImageContext();
UIGraphicsEndImageContext();
return fullImage;
}
图片处理view - 成图,相关推荐
- 图片上加动图怎么弄_用PS把千张图片拼成心爱的人的样子,只需三步!
把千张图片拼成一张图像也就是千图成像,用PS还是很简单的,虽然说我还在存够心爱的人的千张图片的路上,但是这个技巧可以先学上. 教程开始 步骤一:准备好图片,如果图片尺寸不统一,可以用PS的这个自动批量 ...
- Python 基础 之 词云(词的频率统计大小成图)的简单实现(包括图片词云,词云颜色,词的过滤)
Python 基础 之 词云(词的频率统计大小成图)的简单实现(包括图片词云,词云颜色,词的过滤) 目录
- Python爬虫-爬取快看漫画网图片并拼接成漫画长图
Python爬虫-爬取快看漫画网图片并拼接成漫画长图 1.爬取图片 2.拼接图片 1.爬取图片 import os import requests from bs4 import BeautifulS ...
- 系统WallPaper图片可以设置成屏幕大小的图吗?
系统WallPaper图片可以设置成屏幕大小的图吗? 系统默认的Wallpaper图片都是两倍屏宽,主要有2个目的: 1.壁纸可以随着Launcher Workspace的滑动而滑动: 2.屏幕横屏时 ...
- 将图片序列压缩成视频
原文链接:http://blog.csdn.net/carson2005/article/details/7085480 有些时候,我们确实需要将一个图片序列压缩成视频文件,从而方便观看,或者给别人展 ...
- Android代码(Handler的运用),HttpURLConnection的应用,将url图片地址转换成图片。
1 布局文件, <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" xml ...
- Android开发之Glide设置View背景图的方法
先看效果图: 看了下效果还可以,虽然此方法在Glide4.1.2版本已过时但是还可以使用 针对Glide4.0以上版本设置View背景图方法如下:Kotlin版本 package com.xiayiy ...
- graphpad图片怎么导出矢量图_为何我的文章图片总是不满足杂志社要求?
杂志社对于图片的要求往往十分严格,图片分辨率.图片大小.字体格式.颜色模式等等都会有要求,被拒了稿换一个杂志,可能又有一套新的要求,重复劳动让人苦不堪言.今天给大家分享一些SCI论文图片编辑过程中的小 ...
- vs 如何将源文件转换成可执行文件_如何将图片文件转换成PDF文件?
小编的一个朋友是做室内设计的,大家都知道做室内设计或者其它一些关于设计方面的工作都少不了画图.他每天会画很多张图并且还会反复修改,非常麻烦.有的图会因为不小心鼠标或者键盘误点了,导致一些图的数据错误, ...
- bcb quickrep保存为 图片_不容错过的SCI图片处理和组图方法
高质量图片是SCI论文中重要的组成,SCI论文对于图片有较高的要求.图片能使文章整体更具有客观性.真实性和科学性.大多数审稿人和读者在初看SCI文章的时候,也会先粗略看一篇文章中的图片,故而能否将图片 ...
最新文章
- java 反序列化漏洞 利用思路简介
- 洛谷 P2574 XOR的艺术
- sublime按ctrl+B不能运行
- 周末加班重构代码的几点感慨
- c语言程序中unit怎么定义,c ++中的一个定义规则(One definition rule in c++)
- 利用Access-Control-Allow-Origin响应头解决跨域请求
- 数据库原理与应用(SQL Server)笔记 第六章 数据完整性
- 什么是散列表(哈希表)?
- NDK开发基础④增量更新之客户端合并差分包
- 抑制剂拮抗剂等小分子化合物
- [label][WorldPress] 一个很方便查找定位WorldPress源代码位置的网址
- leetcode-841-钥匙和房间 题解
- 【圈外同学】Day01 一个模型,帮你找到真正热爱的
- 引入jquery不起作用 原因
- access数据库的用户名和密码的问题
- 镁光139 8510
- rm删除某文件之外的所有文件
- 【PADS9.5】PADS Logic 绘制原理图
- android中自定义 toast,android 自定义Toast
- 求职,找工作,应聘,面试(一)为什么你没投简历,对方也会给你打电话进行面试邀约?
热门文章
- VC6.0安装番茄助手
- 网络速度在线测试软件,在线网速测试(局域网速度测试工具)
- xscan运行xscan_gui.exe无法打开
- 搞定Android开发环境部署——非常详细的Android开发环境搭建教程
- 电脑tf卡检测不到_tf卡 插入电脑没盘符,但数据恢复软件能检测到异常
- 如何用50块钱在学校吃一个月
- 详解clientHeight、offsetHeight、scrollHeight、offsetTop、scrollTop
- Diffusion Models:生成扩散模型
- 【QT】入门基础教程Qt5
- oa办公系统文件存取错误_出现文件存取错误解决方法