2014-02-12 2 views
0

UIImage를 물리적으로 확장하는 방법으로 대상 너비와 높이를 제외하고 이미지와 완전히 동일한 설정을 가진 비트 맵 컨텍스트를 만들어야합니다.CGImage의 픽셀 당 구성 요소 수를 결정하는 방법은 무엇입니까?

여기 내 코드가 있습니다. 누락 된 부분 : CGBitmapContextCreate의 bytesPerRow 매개 변수에 대해 CGImage의 픽셀 당 구성 요소 수를 결정하려면 어떻게합니까?

CGImageRef cgImage = self.CGImage; 
size_t widthPX = CGImageGetWidth(cgImage); 
size_t heightPX = CGImageGetHeight(cgImage); 
size_t bitsPerComponent = CGImageGetBitsPerComponent(cgImage); 
size_t bitsPerPixel = CGImageGetBitsPerPixel(cgImage); 
size_t bytesPerRow = CGImageGetBytesPerRow(cgImage); 
CGColorSpaceRef colorSpace = CGImageGetColorSpace(cgImage); 
CGColorSpaceModel colorSpaceModel = CGColorSpaceGetModel(colorSpace); 
CGBitmapInfo bitmapInfo = CGImageGetBitmapInfo(cgImage); 

CGContextRef CTX = CGBitmapContextCreate (NULL, destWidth, destHeight, bitsPerComponent, bytesPerRow/잘못!이 소스 너비이다/색 공간, BITMAPINFO!);

답변

3

내 원유 솔루션입니다. 아직 작동하는지 확실하지 않습니다.

size_t bytesPerRow = CGImageGetBytesPerRow(cgImage); 
size_t bytesPerPixel = bytesPerRow/widthPX; 
size_t destBytesPerRow = bytesPerPixel * destWidth; 

내가 시도한 것은 다음과 같습니다. 먼저 행당 바이트 수와 원본 이미지의 픽셀 수를 기준으로 픽셀 당 바이트를 계산합니다. 그런 다음 대상 너비를 곱하여 대상 이미지의 행당 바이트를 가져옵니다.

관련 문제