[iOS 图像处理相关]
//使用CGImage获取并修改图片像素 #define Mask8(x) ( (x) & 0xFF )
#define R(x) ( Mask8(x) )
#define G(x) ( Mask8(x >> 8 ) )
#define B(x) ( Mask8(x >> 16) )
#define A(x) ( Mask8(x >> 24) )
#define RGBAMake(r, g, b, a) ( Mask8(r) | Mask8(g) << 8 | Mask8(b) << 16 | Mask8(a) << 24 ) - (UIImage *)processUsingPixels:(UIImage*)inputImage {
// 1. Get the raw pixels of the image
//定义最高32位整形指针 *inputPixels
UInt32 * inputPixels; //转换图片为CGImageRef,获取参数:长宽高,每个像素的字节数(4),每个R的比特数
CGImageRef inputCGImage = [inputImage CGImage];
NSUInteger inputWidth = CGImageGetWidth(inputCGImage);
NSUInteger inputHeight = CGImageGetHeight(inputCGImage);
CGColorSpaceRef colorSpace = CGColorSpaceCreateDeviceRGB(); NSUInteger bytesPerPixel = ;
NSUInteger bitsPerComponent = ; //每行字节数
NSUInteger inputBytesPerRow = bytesPerPixel * inputWidth; //开辟内存区域,指向首像素地址
inputPixels = (UInt32 *)calloc(inputHeight * inputWidth, sizeof(UInt32)); //根据指针,前面的参数,创建像素层
CGContextRef context = CGBitmapContextCreate(inputPixels, inputWidth, inputHeight,
bitsPerComponent, inputBytesPerRow, colorSpace,
kCGImageAlphaPremultipliedLast | kCGBitmapByteOrder32Big);
//根据目前像素在界面绘制图像
CGContextDrawImage(context, CGRectMake(, , inputWidth, inputHeight), inputCGImage); //接来下就是重点了!!!像素处理--------------------------------------------------------
for (NSUInteger j = ; j < inputHeight; j++) {
for (NSUInteger i = ; i < inputWidth; i++) {
UInt32 * currentPixel = inputPixels + (j * inputWidth) + i;
UInt32 color = *currentPixel;
UInt32 br,thisR,thisG,thisB,thisA;
//这里直接移位获得RBGA的值,以及输出写的非常好!
thisR=R(color);
thisG=G(color);
thisB=B(color);
thisA=A(color);
//NSLog(@"%d,%d,%d,%d",thisR,thisG,thisB,thisA);
br=B(color)-R(color);
*currentPixel = RGBAMake(br, br, br, A(color));
}
}
//创建新图
// 4. Create a new UIImage
CGImageRef newCGImage = CGBitmapContextCreateImage(context);
UIImage * processedImage = [UIImage imageWithCGImage:newCGImage];
//释放
// 5. Cleanup!
CGColorSpaceRelease(colorSpace);
CGContextRelease(context);
free(inputPixels); return processedImage;
}
//=======图像缩放====================================================================
- (UIImage *)scaleImage:(UIImage *)image toScale:(float)scaleSize
{
UIGraphicsBeginImageContext(CGSizeMake(image.size.width * scaleSize, image.size.height * scaleSize));
[image drawInRect:CGRectMake(, , image.size.width * scaleSize, image.size.height * scaleSize)];
UIImage *scaledImage = UIGraphicsGetImageFromCurrentImageContext(); NSLog(@"准备图像裁剪》》》》缩放后图片大小:width %f height %f ",scaledImage.size.width,scaledImage.size.height); UIGraphicsEndImageContext();
return scaledImage;
}
[iOS 图像处理相关]的更多相关文章
- iOS网络相关知识总结
iOS网络相关知识总结 1.关于请求NSURLRequest? 我们经常讲的GET/POST/PUT等请求是指我们要向服务器发出的NSMutableURLRequest的类型; 我们可以设置Reque ...
- iOS网络相关零散知识总结
iOS网络相关零散知识总结 1. URL和HTTP知识 (1) URL的全称是Uniform Resource Locator(统一资源定位符). URL的基本格式 = 协议://主机地址/路径 ...
- 详解OS X和iOS图像处理框架Core Image
转自:http://www.csdn.net/article/2015-02-13/2823961-core-image 摘要:本 文结合实例详解了OS X和iOS图像处理框架Core Image的使 ...
- iOS - 直播相关文章
直播相关文章 直播RTMP可用于测试的服务器地址 FFmpeg avdumpformat输出的tbn.tbc.tbr.PAR.DAR的含义 FFmpeg 3.0 计算视频时长 HLS Streamin ...
- ios 缓存相关信息收集
链接:http://www.cnblogs.com/pengyingh/category/353093.html 使用NSURLCache让本地数据来代替远程UIWebView请求 摘要: 原文作者: ...
- iOS开发-相关文档
关于调试,查看Xcode Overview文档相关部分:http://developer.apple.com/library/ios/documentation/ToolsLanguages/Conc ...
- iOS开发经验相关知识
一. iPhone Size 手机型号 屏幕尺寸 iPhone 4 4s 320 * 480 iPhone 5 5s 320 * 568 iPhone 6 6s 375 * 667 iphone 6 ...
- iOS app 支持HTTPS iOS开发者相关
2016年12月21日更新开发者中心链接https://developer.apple.com/news/?id=12212016b该链接是苹果昨天刚在官网给的正式回复 如下: App Transpo ...
- iOS 地图相关
参考博文:https://blog.csdn.net/zhengang007/article/details/52858198?utm_source=blogxgwz7 1.坐标系 目前常见的坐标系有 ...
随机推荐
- [译]用AngularJS构建大型ASP.NET单页应用(三)
原文地址:http://www.codeproject.com/Articles/808213/Developing-a-Large-Scale-Application-with-a-Single A ...
- 微信公众平台SDK
微信公众平台网址:https://mp.weixin.qq.com/ 服务号说明:给企业和组织提供更强大的业务服务与用户管理能力,帮助企业快速实现全新的公众号服务平台. .NETSDK: Loogn. ...
- Bootstrap系列 -- 6. 列表
一. 普通无序列表 <ul> <li>无序列表项目</li> <li>无序列表项目</li> <li>无序列表项目</li ...
- Windows Phone 8 下载文件进度
后台代码: public partial class MainPage : PhoneApplicationPage { private long siz; private long speed; p ...
- OpenStack 简介
OpenStack是IaaS(基础设施即服务)组件,让任何人都可以自行建立和提供云端运算服务. 此外,OpenStack也用作建立防火墙内的"私有云"(Private Cloud) ...
- MATLAB如何定义函数
自定义函数的途径:M文件函数(M file function)在线函数(Inline Function)匿名函数(Anonymous Function)1.M文件函数范例function c=myad ...
- mysql安装方法
Window版本 1.下载 MySQL Community Server 5.7.16 http://dev.mysql.com/downloads/mysql/ 2.解压 如果想要让MySQL安装在 ...
- 1118sync_binlog innodb_flush_log_at_trx_commit 浅析
转自 http://blog.itpub.net/22664653/viewspace-1063134/ innodb_flush_log_at_trx_commit和sync_binlog 两个参 ...
- Retrofit 2.1 入门
Retrofit 2.1入门 , map); try { Response<String>body=call.execute(); System.out. ...
- [Elasticsearch] 全文搜索 (一) 基础概念和match查询
全文搜索(Full Text Search) 现在我们已经讨论了搜索结构化数据的一些简单用例,是时候开始探索全文搜索了 - 如何在全文字段中搜索来找到最相关的文档. 对于全文搜索而言,最重要的两个方面 ...