2011-12-09 1 views
0

코어 그래픽에서 간단하지만 효과적인 엠보싱 효과를 보았습니다. 잘 작동합니다! 하지만 시뮬레이터에 ... 여기 은 결과입니다코어 그래픽 효과 : 시뮬레이터에서는 작동하지만 장치에서는 작동하지 않습니다.

1st image

은 내가 할 것은 다음 -이 경우 촬상 된 이미지에서, 나는 알파를 꺼내 나는 흰색으로 채우기 . - 제가 를 그레이 스케일이 RGB 이미지 변형 - 제가

난 다음 파라미터들에 영향 만들 정의 메소드 호출이 화상의 색상을 반전 :

  • canvasImg을 : 반투명 이미지에 마스크
  • maskImg : 난 그냥 만들어 그레이 스케일과 반전 이미지 :

2nd image

  • opacitity : 결과 이미지

있어서 다음 간단하게 마스크의 불투명도는 그림자 oppacity을 적용하고 새로운있는 UIImage 반환한다. 왜 시뮬레이터에서 작동하는지, 장치가 이해되지 않습니다. 장치에서 실행 중일 때, null이 아닌 UIImage를 얻습니다. 도와주세요!

- (UIImage *)stampImage:(UIImage *)canvasImg withMask:(UIImage *)maskImg withOpacity:(CGFloat)opacity 
{ 
//Creating the mask Image 
CGContextRef mainViewContentContext; 
CGColorSpaceRef colorSpace; 
colorSpace = CGColorSpaceCreateDeviceRGB(); 
mainViewContentContext = CGBitmapContextCreate(NULL, maskImg.size.width, maskImg.size.height, 8, 0, colorSpace, kCGImageAlphaPremultipliedLast); 
CGColorSpaceRelease(colorSpace); 

if (mainViewContentContext == NULL) return NULL; 

CGContextClipToMask(mainViewContentContext, CGRectMake(0, 0, maskImg.size.width, maskImg.size.height), maskImg.CGImage); 
CGContextDrawImage(mainViewContentContext, CGRectMake(0, 0, maskImg.size.width, maskImg.size.height), canvasImg.CGImage); 
CGContextSetAllowsAntialiasing(mainViewContentContext, true); 
CGContextSetShouldAntialias(mainViewContentContext, true); 
CGImageRef mainViewContentBitmapContext = CGBitmapContextCreateImage(mainViewContentContext); 
CGContextRelease(mainViewContentContext); 
UIImage *maskedImage = [UIImage imageWithCGImage:mainViewContentBitmapContext]; 
CGImageRelease(mainViewContentBitmapContext); 

//Giving some Drop shadows 
CGColorSpaceRef colourSpace = CGColorSpaceCreateDeviceRGB(); 
CGContextRef shadowContext = CGBitmapContextCreate(NULL, maskedImage.size.width + 10, maskedImage.size.height + 10, 
                CGImageGetBitsPerComponent(maskedImage.CGImage), 0, 
                colourSpace, kCGImageAlphaPremultipliedLast); 
CGColorSpaceRelease(colourSpace); 
CGContextSetShadowWithColor(shadowContext, CGSizeMake(0, -1), 1, [UIColor colorWithWhite:1.0 alpha:0.3].CGColor); 
CGContextSetAllowsAntialiasing(shadowContext, true); 
CGContextSetShouldAntialias(shadowContext, true); 
CGContextDrawImage(shadowContext, CGRectMake(0, 10, maskedImage.size.width, maskedImage.size.height), maskedImage.CGImage); 
CGImageRef shadowedCGImage = CGBitmapContextCreateImage(shadowContext); 
CGContextRelease(shadowContext); 

UIImage *stampImg = [UIImage imageWithCGImage:shadowedCGImage]; 
CGImageRelease(shadowedCGImage); 

return stampImg; 

}

+1

기기에서 어떤 결과가 나타 납니까? –

+0

단순히'nil'을 되 찾는다면'mainViewContentContext'가'NULL'이 아니라는 것을 확인 했습니까? 'CGBitmapContextCreate()'에 허용 된 입력이 데스크톱 대 장치마다 다를 수 있습니다. –

+0

Kevin에게 감사드립니다. CGBitmapContextCreate()에 대해 생각하지 않아도 문제가 될 수 있습니다. 나는 그것에 대해 살펴볼 것이다. – DZenBot

답변

1

는 또한 대 시뮬레이터 장치의 메모리 제한주의 : 여기

코드이다. 나는 시뮬레이터에서 잘 빌드되고 실행될 CG 로직을 가졌다. 동일한 로직이 생성되어 장치에서 오류가 발생하지 않지만 시각적 결과는 원하는 것이 아닙니다. 상당히 작은 이미지에서 로직을 사용하여 장치에서 작동하는지 확인하는 것이 좋습니다. 나는 장치가 더 큰 이미지를 위해 그것을 끄기 위해 마력을 갖지 않았기 때문에 내가 생각해내는 아주 멋진 이미지 마스킹 물건들을 버려야 만했다.

+0

빙고! 처음으로 코드가 아니라 캔버스 이미지였습니다. 그래서 방금 새 이미지, 반투명, 회색 음영으로 모든 것을 기기에서 만들었습니다! 답장을 보내 주신 Kevin과 jstevenco에게 감사드립니다. P – DZenBot