2012-02-19 2 views
0

iOS 용 이미지에 특정 맞춤 필터 효과를 만들려고합니다. 지금까지 CGBitmapContextCreate를 사용하여 원시 데이터를 가져 오려고했습니다. 그러나 rawData를 수정하는 방법에 대한 아이디어는 없습니다. 그것에 대한 계산을 수행하기를 바랍니다. 원시 데이터로 픽셀 단위로 효과를 내기를 희망하지만 조작 방법을 모릅니다.CoreGraphics를 사용하여 이미지 원시 데이터에 대한 계산을 수행하는 방법은 무엇입니까?

또한 비트 맵 컨텍스트를 UIImage에 그릴 수있는 방법을 모르겠으므로 UIImageView에서 완성 된 제품을 렌더링 할 수 있습니다.

누군가가 저에게 어떻게 달성 할 수 있을지 알려줄 수 있습니까?

여기 내 코드는 지금까지의 :

// First get the image into your data buffer 
CGImageRef imageRef = imageView.image.CGImage; 
NSUInteger width = CGImageGetWidth(imageRef); 
NSUInteger height = CGImageGetHeight(imageRef); 
CGColorSpaceRef colorSpace = CGColorSpaceCreateDeviceRGB(); 
unsigned char *rawData = calloc(height * width * 4, sizeof(unsigned char)); 
NSUInteger bytesPerPixel = 4; 
NSUInteger bytesPerRow = bytesPerPixel * width; 
NSUInteger bitsPerComponent = 8; 
CGContextRef context = CGBitmapContextCreate(rawData, width, height, 
              bitsPerComponent, bytesPerRow, colorSpace, 
              kCGImageAlphaPremultipliedLast | kCGBitmapByteOrder32Big); 
CGColorSpaceRelease(colorSpace); 

CGContextDrawImage(context, CGRectMake(0, 0, width, height), imageRef); 

//perform calculations on rawData? or context? not sure!! i hope to effect pixel by pixel. 


//am i doing this correctly? 
UIImage *newImage = UIGraphicsGetImageFromCurrentImageContext(); 
UIGraphicsEndImageContext(); 
//set the imageview with the new image 
[imageView setImage:newImage]; 
CGContextRelease(context); 

답변

0

당신은 거의있다. 다음을 통해 RGB 및 알파 채널에서 거래를 수행 할 수 있습니다.

for (NSUInteger i = 0 ; i < rawDataSpace ; i+=4) { 
     rawData[i+0] = ...    
     rawData[i+1] = ...    
     rawData[i+2] = ...    
     rawData[i+3] = ...  // = Alpha channel   
관련 문제