2013-04-15 6 views
0

이미지를 한 형식 (.png)에서 다른 이미지 형식 (.img 형식)으로 변환하고 싶습니다. 동일한 이미지 형식에 대해 rgba 값을 검색하고 수정할 수있었습니다. 다른 이미지 형식으로 변환해야하는 추가 작업이 있습니까?iOS에서 새 비트 맵을 만들고 검색하는 방법

비어있는 비트 맵을 만들었으므로이 비트 맵 이미지를 그릴 수 있습니다.

CGImageRef cgimage = image.CGImage; 

size_t width = CGImageGetWidth(cgimage); 
size_t height = CGImageGetHeight(cgimage); 

size_t bytesPerRow = CGImageGetBytesPerRow(cgimage); 
size_t bytesPerPixel = CGImageGetBitsPerPixel(cgimage); 
size_t bitsPerComponent = CGImageGetBitsPerComponent(cgimage); 
size_t bytes_per_pixel = bytesPerPixel/bitsPerComponent; 

CGBitmapInfo bitmapInfo = CGImageGetBitmapInfo(cgimage); 

CGColorSpaceRef colorSpace = CGColorSpaceCreateDeviceRGB(); 
unsigned char *rawData = malloc(height * width * 4); 
memset(rawData, 0, height * width * 4); 

CGContextRef context = CGBitmapContextCreate(rawData, width, height, bitsPerComponent, bytesPerRow, colorSpace, bitmapInfo); 

CGContextDrawImage(context, CGRectMake(0, 0, width, height), image.CGImage); 

수정 된 rgba 값으로 출력 비트 맵을 채우는 기능이 iOS에 있습니까?

+0

"iOS에서 비트 맵으로 데이터를 그리는 방법"이란 무엇을 의미합니까? 특정 지점에서 픽셀을 선택하는 것에 대해 이야기하고 있습니까? –

+0

@TBlue : 제목을 수정했습니다. – Ram

+0

더 많이 읽을수록 혼란스러워집니다. 귀하가 지시하는 확장자 중 하나 (.img)는 10 년 전이나 디스크 이미지 형식으로 사용되었습니다. –

답변

2

그것은 다음과 같이 보일 것입니다 : 당신이 데이터를 조작 할 경우

UIImage *image = self.theImage; 
CGImageRef imageRef = [image CGImage]; 
NSUInteger width = CGImageGetWidth(imageRef); 
NSUInteger height = CGImageGetHeight(imageRef); 
CGColorSpaceRef colorSpace = CGColorSpaceCreateDeviceRGB(); 
NSMutableData *data = [[NSMutableData alloc] initWithCapacity:height * width * 4]; 
unsigned char *rawData = data.mutableBytes; 
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); 
CGContextRelease(context); 

int byteIndex = (bytesPerRow * 0) + 0 * bytesPerPixel; 

, 당신은 byteIndex 반복. 그것이 당신이 찾고있는 것이기를 바랍니다.