iOS中图形图像处理第一部分:位图图像原图修改
demo地址:http://download.csdn.net/download/jueyi1127/10175882
在图形图像处理教程的第一节,主要讲解位图图像原图的修改。一但你明白基本的图形处理方法,那么其它的相关内容你也会较容易的弄明白。在教程的第二部分,主要介绍另外的三种修改图像
- // 1.
- CGImageRef inputCGImage = [image CGImage];
- NSUInteger width = CGImageGetWidth(inputCGImage);
- NSUInteger height = CGImageGetHeight(inputCGImage);
- // 2.
- NSUInteger bytesPerPixel = 4;
- NSUInteger bytesPerRow = bytesPerPixel * width;
- NSUInteger bitsPerComponent = 8;
- UInt32 * pixels;
- pixels = (UInt32 *) calloc(height * width, sizeof(UInt32));
- // 3.
- CGColorSpaceRef colorSpace = CGColorSpaceCreateDeviceRGB();
- CGContextRef context = CGBitmapContextCreate(pixels, width, height, bitsPerComponent, bytesPerRow, colorSpace, kCGImageAlphaPremultipliedLast | kCGBitmapByteOrder32Big);
- // 4.
- CGContextDrawImage(context, CGRectMake(0, 0, width, height), inputCGImage);
- // 5. Cleanup
- CGColorSpaceRelease(colorSpace);
- CGContextRelease(context);
- // 1.
- #define Mask8(x) ( (x) & 0xFF )
- #define R(x) ( Mask8(x) )
- #define G(x) ( Mask8(x >> 8 ) )
- #define B(x) ( Mask8(x >> 16) )
- NSLog(@"Brightness of image:");
- // 2.
- UInt32 * currentPixel = pixels;
- for (NSUInteger j = 0; j < height; j++) {
- for (NSUInteger i = 0; i < width; i++) {
- // 3.
- UInt32 color = *currentPixel;
- printf("%3.0f ", (R(color)+G(color)+B(color))/3.0);
- // 4.
- currentPixel++;
- }
- printf("\n");
- }
- - (void)setupWithImage:(UIImage*)image {
- UIImage * fixedImage = [image imageWithFixedOrientation];
- self.workingImage = fixedImage;
- // Commence with processing!
- [ImageProcessor sharedProcessor].delegate = self;
- [[ImageProcessor sharedProcessor] processImage:fixedImage];
- }
- // [self setupWithImage:[UIImage imageNamed:@"ghost_tiny.png"]];
- CGFloat ghostImageAspectRatio = ghostImage.size.width / ghostImage.size.height;
- NSInteger targetGhostWidth = inputWidth * 0.25;
- CGSize ghostSize = CGSizeMake(targetGhostWidth, targetGhostWidth / ghostImageAspectRatio);
- CGPoint ghostOrigin = CGPointMake(inputWidth * 0.5, inputHeight * 0.2);
- NSUInteger ghostBytesPerRow = bytesPerPixel * ghostSize.width;
- UInt32 * ghostPixels = (UInt32 *)calloc(ghostSize.width * ghostSize.height, sizeof(UInt32));
- CGContextRef ghostContext = CGBitmapContextCreate(ghostPixels, ghostSize.width, ghostSize.height,
- bit sPerComponent, ghostBytesPerRow, colorSpace,
- kCG ImageAlphaPremultipliedLast | kCGBitmapByteOrder32Big);
- CGContextDrawImage(ghostContext, CGRectMake(0, 0, ghostSize.width, ghostSize.height),ghostCGImage);
- NewColor = TopColor * TopColor.Alpha + BottomColor * (1 - TopColor.Alpha)
- NSUInteger offsetPixelCountForInput = ghostOrigin.y * inputWidth + ghostOrigin.x;
- for (NSUInteger j = 0; j < ghostSize.height; j++) {
- for (NSUInteger i = 0; i < ghostSize.width; i++) {
- UInt32 * inputPixel = inputPixels + j * inputWidth + i + offsetPixelCountForInput;
- UInt32 inputColor = *inputPixel;
- UInt32 * ghostPixel = ghostPixels + j * (int)ghostSize.width + i;
- UInt32 ghostColor = *ghostPixel;
- // Do some processing here
- }
- }
- // Blend the ghost with 50% alpha
- CGFloat ghostAlpha = 0.5f * (A(ghostColor) / 255.0);
- UInt32 newR = R(inputColor) * (1 - ghostAlpha) + R(ghostColor) * ghostAlpha;
- UInt32 newG = G(inputColor) * (1 - ghostAlpha) + G(ghostColor) * ghostAlpha;
- UInt32 newB = B(inputColor) * (1 - ghostAlpha) + B(ghostColor) * ghostAlpha;
- // Clamp, not really useful here :p
- newR = MAX(0,MIN(255, newR));
- newG = MAX(0,MIN(255, newG));
- newB = MAX(0,MIN(255, newB));
- *inputPixel = RGBAMake(newR, newG, newB, A(inputColor));
- // Create a new UIImage
- CGImageRef newCGImage = CGBitmapContextCreateImage(context);
- UIImage * processedImage = [UIImage imageWithCGImage:newCGImage];
- return processedImage;
- // Convert the image to black and white
- for (NSUInteger j = 0; j < inputHeight; j++) {
- for (NSUInteger i = 0; i < inputWidth; i++) {
- UInt32 * currentPixel = inputPixels + (j * inputWidth) + i;
- UInt32 color = *currentPixel;
- // Average of RGB = greyscale
- UInt32 averageColor = (R(color) + G(color) + B(color)) / 3.0;
- *currentPixel = RGBAMake(averageColor, averageColor, averageColor, A(color));
- }
- }
- CGColorSpaceRelease(colorSpace);
- CGContextRelease(context);
- CGContextRelease(ghostContext);
- free(inputPixels);
- free(ghostPixels);
iOS中图形图像处理第一部分:位图图像原图修改相关推荐
- iOS中的图像处理(一)——基础滤镜
最近在稍微做一些整理,翻起这部分的代码,发现是两个多月前的了. 这里讨论的是基于RGBA模型下的图像处理,即将变换作用在每个像素上. 代码是以UIImage的category形式存在的: [cpp] ...
- 【图形图像处理】之位图图像和矢量图形有何区别?
位图特点:会因为图形放大而变得图形不可辨认.矢量图特点:图形放大缩小不会改变图形辨认度. 一.主体不同 1.位图图像:由称作像素(图片元素)的单个点组成的. 2.矢量图形:根据几何特性来绘制图形,矢量 ...
- OpenCV-Python图形图像处理:利用TopHat顶帽获取背景色中的噪点
☞ ░ 前往老猿Python博客 https://blog.csdn.net/LaoYuanPython ░ 一.顶帽简介 顶帽(Top Hat),又称"礼帽"运算,其结果图像为原 ...
- 计算机技术在图形图像处理中的应用,计算机技术在图形图像处理中的应用研究...
计算机技术在图形图像处理中的应用研究 摘要随着人们生存生活的发展和进步,计算机图形和图像的处理技术就会越来越好,越来越形象和逼真了.计算机图形和图像的处理技术在很多的领域里发挥着非常重要的作用.本文主 ...
- 国内外计算机专业图形图像处理课程现状,中职学校Photoshop图形图像处理课程的教学反思...
施树英 [摘 要]本文分析中职学校 Photoshop 课程的教学现状,并结合教学实际情况,从课程本身.学生.教师的教学方法三个层面对 Photoshop 图形图像处理课程教学进行反思,提出联系生活激 ...
- 中职计算机图形图像课程标准,计算机图形与图形图像处理技术的相互结合
钟志锋 [摘 要] 随着社会的不断发展和进步,中职教育也越发需要进步和更新才可以适应新时期对中职学生的要求.而计算机图形与图形图像处理技术也是顺应时代而生的新兴技术.计算机图形与图形图像处理技术已经成 ...
- 计算机技术在美术方面的应用,计算机技术在图形图像处理中的应用
周明伟 王艳 摘要:计算机技术作为当下流行的技术之一,受到了越来越多的关注,无论是人们的日程生活,还是各行各业的发展生产过程当中都离不开计算机技术.在科学技术高度发达的今天,计算机技术得到了不断地创新 ...
- 计算机在多媒体技术中的应用研究,计算机技术在图形图像处理中的应用研究
计算机技术在图形图像处理中的应用研究 随着信息技术的发展,图像处理技术在日常生活中的应用越来越普遍,下面是小编搜集整理的一篇探究计算机技术在图形图像处理应用的论文范文,供大家阅读参考. 摘要:随着计算 ...
- 手机直播系统开发中关于iOS获取图形验证码功能
在手机直播系统开发中关于iOS获取图形验证码功能介绍,首先进入注册页面后请求图形验证码接口获取图形验证码的数字组合,然后加载到相应的页面上,在图形验证码页面我们定义了几个属性,字符串的数量.显示的线条 ...
最新文章
- NOIP2010-普及组复赛模拟试题-第一题-手机
- ERROR Streaming result set com.mysql.jdbc.RowDataDynamic@1d5a7f6 is still active. No statements may
- 50 CO配置-控制-获利能力分析-维护经营关注点
- 唏嘘!一代手机OS退场:没生态、没开发者是失败主因
- 图解算法之排序算法(5)——归并排序
- 工作中最重要的个人品质--独立
- python中json怎么转换成字典
- 太阳方位角 太阳天顶角
- 如何在Ubuntu 16.04上使用ProxySQL缓存优化MySQL查询
- attempted to return null from a method with a primitive return type (int).
- 最新文本转语音的接口(免费),百度语音作废
- python在冒号处显示语法错误_python冒号错误语法无效
- ENVI|一天一个小技能|APP STORE浏览并下载矢量数据
- 基于Xilinx Kintex-7 FPGA K7 XC7K325T PCIeX8 四路光纤卡226
- 神经网络和深度神经网络,图神经网络和神经网络
- Linux版csgo调全屏窗口,csgo全屏和全屏窗口 哔哩哔哩直播姬黑屏解决方法
- Debian9的各个版本的下载地址
- Prime Day首日遇宕机和罢工,AWS遭网友群嘲太low?
- 用友计算机审计实验步骤,计算机审计上机实验报告模板详解.doc
- 2011:那些逝去的IT英才