图像处理之CPU图片滤镜
来源:互联网 发布:以网络为话题的作文 编辑:程序博客网 时间:2024/05/23 01:01
处理之前的图片
// 灰色处理 Here is the code for sepia image
- (UIImage *)imageProcessedOnCPU:(UIImage *)imageToProcess;{ CFAbsoluteTime elapsedTime, startTime = CFAbsoluteTimeGetCurrent(); CGImageRef cgImage = [imageToProcess CGImage]; CGImageRetain(cgImage); CGDataProviderRef provider = CGImageGetDataProvider(cgImage); CFDataRef bitmapData = CGDataProviderCopyData(provider); UInt8* data = (UInt8*)CFDataGetBytePtr(bitmapData); CGImageRelease(cgImage); int width = imageToProcess.size.width; int height = imageToProcess.size.height; NSInteger myDataLength = width * height * 4; for (int i = 0; i < myDataLength; i+=4) { UInt8 r_pixel = data[i]; UInt8 g_pixel = data[i+1]; UInt8 b_pixel = data[i+2]; int outputRed = (r_pixel * .393) + (g_pixel *.769) + (b_pixel * .189); int outputGreen = (r_pixel * .349) + (g_pixel *.686) + (b_pixel * .168); int outputBlue = (r_pixel * .272) + (g_pixel *.534) + (b_pixel * .131); if(outputRed>255)outputRed=255; if(outputGreen>255)outputGreen=255; if(outputBlue>255)outputBlue=255; data[i] = outputRed; data[i+1] = outputGreen; data[i+2] = outputBlue; } CGDataProviderRef provider2 = CGDataProviderCreateWithData(NULL, data, myDataLength, NULL); int bitsPerComponent = 8; int bitsPerPixel = 32; int bytesPerRow = 4 * width; CGColorSpaceRef colorSpaceRef = CGColorSpaceCreateDeviceRGB(); CGBitmapInfo bitmapInfo = kCGBitmapByteOrderDefault; CGColorRenderingIntent renderingIntent = kCGRenderingIntentDefault; CGImageRef imageRef = CGImageCreate(width, height, bitsPerComponent, bitsPerPixel, bytesPerRow, colorSpaceRef, bitmapInfo, provider2, NULL, NO, renderingIntent); CGColorSpaceRelease(colorSpaceRef); CGDataProviderRelease(provider2); CFRelease(bitmapData); UIImage *sepiaImage = [UIImage imageWithCGImage:imageRef]; CGImageRelease(imageRef); elapsedTime = CFAbsoluteTimeGetCurrent() - startTime; processingTimeForCPURoutine = elapsedTime * 1000.0; return sepiaImage;}
调用
UIImage *inputImage = [UIImage imageNamed:@"Lambeau.jpg"];[self imageProcessedOnCPU:inputImage];
处理之后的图片
黑白处理 Here is the code for Black & White effect
- (UIImage*) createGrayCopy:(UIImage*) source { int width = source.size.width; int height = source.size.height; CGColorSpaceRef colorSpace = CGColorSpaceCreateDeviceGray(); CGContextRef context = CGBitmapContextCreate (nil, width, height, 8, // bits per component 0, colorSpace, kCGImageAlphaNone); CGColorSpaceRelease(colorSpace); if (context == NULL) { return nil; } CGContextDrawImage(context, CGRectMake(0, 0, width, height), source.CGImage); UIImage *grayImage = [UIImage imageWithCGImage:CGBitmapContextCreateImage(context)]; CGContextRelease(context); return grayImage;}
0 0
- 图像处理之CPU图片滤镜
- 图像处理之CoreImage图片滤镜
- 图像处理算法之滤镜
- 【Android图像处理】图像处理之-幻觉滤镜
- 【Android图像处理】图像处理之-极速奔驰滤镜
- 【Android图像处理】图像处理之-马赛克滤镜
- iOS图片处理之滤镜效果
- iOS滤镜 图片处理
- Android图像处理之镜像和简单滤镜效果
- Atitit 图像处理之仿油画效果 Oilpaint油画滤镜 水彩画 漫画滤镜 v2
- android 图像处理滤镜系列
- 图像处理之 图片翻转
- 图像处理之图片展示
- opengles图像处理之图片锐化处理
- IOS 图片滤镜效果处理
- GPUImage混合滤镜处理图片
- android 图片处理 (滤镜,图片位置)
- android 图片处理 (滤镜,图片位置)
- 利用WinDbg分析C#程序产生的转储文件
- Android Studio主题设置(界面背景,字体颜色等)
- 敏捷开发过程中如何开发高质量的软件
- 访问国外网站
- 用冒泡法对20个整数排序
- 图像处理之CPU图片滤镜
- 怎样让动态库(static library)中的category变得可用
- Listview滑动时不加载数据,停下来时加载数据,让App更优
- iOS从零基础到精通就业-C语言入门 1 变量的定义
- 爱流量协议分析
- 查询的时候将多行和并为一行的多列
- 基于TQ2440的小车(4)网络编程控制
- Android开发资源
- AlertDialog(对话框)的介绍和使用