2
나는 CGContextRef
을 가지고 있으며 그 위에 그려서 알파를 지정할 수 있으며, 시도해 보았다면 완벽하게 작동합니다. 그러나, 나는 현재 (빨강 또는 초록색), 그러나 어떤 블렌드 모드를 선택하면, 그것은 알파로 으로 그리기 때문에 1
으로 설정됩니다. 올바른 색상을 그리는 것은 실제로 가능한 옵션이 아닙니다. UIImage
을 파일 시스템에서로드 할 수 있기를 원하므로 어떻게해야합니까?Colourise CGContextRef 그러나 알파 보존
편집 -
UIGraphicsBeginImageContext(CGSizeMake(width,height));
CGContextRef contextRef = UIGraphicsGetCurrentContext();
CGContextClearRect(contextRef, CGRectMake(0.0f, 0.0f, width, height));
CGContextSetRGBStrokeColor(contextRef, 0.0f, 0.0f, 0.0f, 1.0f);
CGContextSetRGBFillColor(contextRef, 1.0f, 1.0f, 1.0f, 1.0f);
CGContextSetLineWidth(contextRef, lineWidth);
CGContextBeginPath(contextRef);
CGContextMoveToPoint(contextRef, points[0].x, points[0].y);
for (int i = 1; i < 4; i++) {
CGContextAddLineToPoint(contextRef, points[i].x, points[i].y);
}
CGContextAddLineToPoint(contextRef, points[0].x, points[0].y); // Encloses shape
CGContextDrawPath(contextRef, kCGPathFillStroke);
[color setFill];
CGContextBeginPath(contextRef);
CGContextSetBlendMode(contextRef, kCGBlendModeMultiply);
CGContextAddRect(contextRef, CGRectMake(0.0f, 0.0f, width, height));
CGContextDrawPath(contextRef, kCGPathFill);
UIImage *image = UIGraphicsGetImageFromCurrentImageContext();
UIGraphicsEndImageContext();
감사 예 코드 (폭 및 높이가 가리키는 소정 플로트 100 %의 불투명도와 UIColor 컨텍스트 및 색 안에 놓여 CGPoints 모든 배열이다) 너의 도움을 위해 미리 너
jrtc27
문제를 더 잘 볼 수 있도록 몇 가지 예제 코드를 제공해 주시겠습니까? –
제 편집을 참조하십시오. – jrtc27
좋아,이게 도움이된다. 네가 생각하는 방식을 이해하려고 노력하고있어, 내가 맞는지 말해봐. 여기에서 볼 수있는 것은 투명도가없는 검은 색 테두리가있는 흰색 직사각형을 그리려는 것입니다. 그런 다음 알 수없는 기능을 수행합니다 [color setFill]; 나는 그것이 무엇을하는지 모른다. (비록 이름이 그들 자신을 위해 말하더라도, 당신은 우리에게 그 정보를 너무주고 싶을지도 모른다). 그런 다음 이전 직사각형 위에 같은 치수의 다른 경로를 그립니다. 그런 다음 그림을 가져 와서 해당 이미지에 저장하고 싶습니다. var. –