0
마스크를 사용하십시오. 마스크는 투명한 배경을 가진 보통 검은 색 PNG 이미지입니다. 여기 나는 기본 이미지 크기의 보통 흰색 이미지를 만듭니다. 그런 다음 필요한 위치의 흰색 이미지에 마스크를 추가하십시오. 그런 다음 maskImage : WithMask 메서드는 검정 영역 만 제거하기 때문에 마스크를 반전시킵니다. 그래서 마스크처럼 보이는 구멍이있는 기본 이미지가 있습니다. 내가 원하는 위치에. 그리고 그것은 작동합니다. 그러나 다른 위치에 구멍을 하나 더 자르려고하면 - 충돌합니다. 제발 말해줘. 내 잘못이야? (때문에) 유지 실종/릴리스UIImage에서 구멍을 자르는 방법?
- (UIImage *)createWhiteImageWithSize:(CGSize)size
{
UIGraphicsBeginImageContext(size);
CGContextSetRGBFillColor(UIGraphicsGetCurrentContext(), 255, 255, 255, 1);
CGContextFillRect (UIGraphicsGetCurrentContext(), CGRectMake (0, 0, size.width, size.height));
UIImage *resultImage = UIGraphicsGetImageFromCurrentImageContext();
UIGraphicsEndImageContext();
return resultImage;
}
- (UIImage *) mergeImage:(UIImage *)backImage with:(UIImage *)frontImage onPosition:(CGPoint)position
{
CGSize finalSize = backImage.size;
CGSize impositionSize = frontImage.size;
UIGraphicsBeginImageContext(finalSize);
[backImage drawInRect:CGRectMake(0, 0, finalSize.width, finalSize.height)];
[frontImage drawInRect:CGRectMake(position.x, position.y, impositionSize.width, impositionSize.height)];
UIImage *resultImage = UIGraphicsGetImageFromCurrentImageContext();
UIGraphicsEndImageContext();
return resultImage;
}
- (UIImage*) maskImage:(UIImage *)image withMask:(UIImage *)maskImage
{
CGImageRef maskRef = maskImage.CGImage;
CGImageRef mask = CGImageMaskCreate(CGImageGetWidth(maskRef),
CGImageGetHeight(maskRef),
CGImageGetBitsPerComponent(maskRef),
CGImageGetBitsPerPixel(maskRef),
CGImageGetBytesPerRow(maskRef),
CGImageGetDataProvider(maskRef), NULL, false);
CGImageRef masked = CGImageCreateWithMask([image CGImage], mask);
return [UIImage imageWithCGImage:masked];
}
- (UIImage *)invertImage:(UIImage *)originalImage
{
UIGraphicsBeginImageContext(originalImage.size);
CGContextSetBlendMode(UIGraphicsGetCurrentContext(), kCGBlendModeCopy);
[originalImage drawInRect:CGRectMake(0, 0, originalImage.size.width, originalImage.size.height)];
CGContextSetBlendMode(UIGraphicsGetCurrentContext(), kCGBlendModeDifference);
CGContextSetFillColorWithColor(UIGraphicsGetCurrentContext(),[UIColor whiteColor].CGColor);
CGContextFillRect(UIGraphicsGetCurrentContext(), CGRectMake(0, 0, originalImage.size.width, originalImage.size.height));
UIImage *returnImage = UIGraphicsGetImageFromCurrentImageContext();
UIGraphicsEndImageContext();
return returnImage;
}
어떤 응용 프로그램이 충돌합니까? 오류가 무엇입니까? –
@MikeM 메소드에서 발생합니다. maskImage : withMask in line 'CGImageRef masked = CGImageCreateWithMask ([image CGImage], mask);' 여기에 마스크는 주소가 있지만 가면 값은 030입니다. – likecatfood
뜻은 0x0입니다. – likecatfood