0
CGContextDrawImage가 상당히 비쌀 수 있으므로 픽셀 데이터를 검사하는 동안 데이터 양을 최소화하려고합니다. 두 개의 이미지와 교차로의 CGRect가있는 경우 CGContextDrawImage를 각각 독립적으로 그릴 수 있습니까 (결과적으로 이미지 중 하나의 교차가 포함 된 두 개의 CGContextRef가 생성됩니다). 여기 두 이미지의 교차 만 포함하는 CGContextDrawImage
당신이 정말CGBitmapContext
를 원하지 않는다면 당신이 그들을 그릴 필요가 없습니다, 음 ...
CGImageRef imageRef = [image CGImage];
NSUInteger width = rectIntersect.size.width;
NSUInteger height = rectIntersect.size.height;
CGColorSpaceRef colorSpace = CGColorSpaceCreateDeviceRGB();
unsigned char *rawData = (unsigned char*) 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);
// rectIntersect down here contains the intersection of the two images...
CGContextDrawImage(context, rectIntersect, imageRef);
내가 CGBitmapContext로 그리는 이유는 특정 색상이나 알파 픽셀의 좌표를 저장해야하기 때문입니다. 그래도 실제로 그려진 결과를 화면에 표시 할 필요는 없습니다. CGBitmapContext없이 원래 픽셀 데이터에 액세스 할 수 있습니까? –
[기술 Q & A QA1509 : CGImage 객체에서 픽셀 데이터 가져 오기] (https://developer.apple.com/library/mac/#qa/qa1509/_index.html) –
CGImageCreateWithImageInRect는 내가 찾고있는 것입니다. 추가 링크를 제공하면 코드를 간소화 할 수 있습니다. 감사! –