मैं गोलाकार कोनों के साथ आईफोन पर छवियों को आकर्षित करने की कोशिश कर रहा हूं, संपर्क ऐप में एक ला संपर्क छवियां। मेरे पास आम तौर पर काम करने वाला कोड है, लेकिन यह कभी-कभी EXEC_BAD_ACCESS
- KERN_INVALID_ADDRESS
के साथ UIImage ड्राइंग रूटीन के अंदर दुर्घटनाग्रस्त हो जाता है। मैंने सोचा कि यह cropping question से संबंधित हो सकता है, मैंने कुछ हफ्ते पहले पूछा था, लेकिन मेरा मानना है कि मैं क्लिपिंग पथ को सही तरीके से स्थापित कर रहा हूं।UIImage पर गोलाकार कॉर्नर
यहां कोड है जिसका उपयोग मैं कर रहा हूं - जब यह क्रैश नहीं होता है, तो परिणाम ठीक दिखता है और कोई भी समान दिखने वाला दिखता है, वह कोड उधार लेने के लिए स्वतंत्र होता है।
- (UIImage *)borderedImageWithRect: (CGRect)dstRect radius:(CGFloat)radius {
UIImage *maskedImage = nil;
radius = MIN(radius, .5 * MIN(CGRectGetWidth(dstRect), CGRectGetHeight(dstRect)));
CGRect interiorRect = CGRectInset(dstRect, radius, radius);
UIGraphicsBeginImageContext(dstRect.size);
CGContextRef maskedContextRef = UIGraphicsGetCurrentContext();
CGContextSaveGState(maskedContextRef);
CGMutablePathRef borderPath = CGPathCreateMutable();
CGPathAddArc(borderPath, NULL, CGRectGetMinX(interiorRect), CGRectGetMinY(interiorRect), radius, PNDegreeToRadian(180), PNDegreeToRadian(270), NO);
CGPathAddArc(borderPath, NULL, CGRectGetMaxX(interiorRect), CGRectGetMinY(interiorRect), radius, PNDegreeToRadian(270.0), PNDegreeToRadian(360.0), NO);
CGPathAddArc(borderPath, NULL, CGRectGetMaxX(interiorRect), CGRectGetMaxY(interiorRect), radius, PNDegreeToRadian(0.0), PNDegreeToRadian(90.0), NO);
CGPathAddArc(borderPath, NULL, CGRectGetMinX(interiorRect), CGRectGetMaxY(interiorRect), radius, PNDegreeToRadian(90.0), PNDegreeToRadian(180.0), NO);
CGContextBeginPath(maskedContextRef);
CGContextAddPath(maskedContextRef, borderPath);
CGContextClosePath(maskedContextRef);
CGContextClip(maskedContextRef);
[self drawInRect: dstRect];
maskedImage = UIGraphicsGetImageFromCurrentImageContext();
CGContextRestoreGState(maskedContextRef);
UIGraphicsEndImageContext();
return maskedImage;
}
और यहां क्रैश लॉग है। यह वही दिखता है जब भी मैं इन दुर्घटनाओं
Exception Type: EXC_BAD_ACCESS (SIGSEGV) Exception Codes: KERN_INVALID_ADDRESS at 0x6e2e6181 Crashed Thread: 0 Thread 0 Crashed: 0 com.apple.CoreGraphics 0x30fe56d8 CGGStateGetRenderingIntent + 4 1 libRIP.A.dylib 0x33c4a7d8 ripc_RenderImage + 104 2 libRIP.A.dylib 0x33c51868 ripc_DrawImage + 3860 3 com.apple.CoreGraphics 0x30fecad4 CGContextDelegateDrawImage + 80 4 com.apple.CoreGraphics 0x30feca40 CGContextDrawImage + 368 5 UIKit 0x30a6a708 -[UIImage drawInRect:blendMode:alpha:] + 1460 6 UIKit 0x30a66904 -[UIImage drawInRect:] + 72 7 MyApp 0x0003f8a8 -[UIImage(PNAdditions) borderedImageWithRect:radius:] (UIImage+PNAdditions.m:187)
आप क्यों करते हैं CGContextSaveGState() और CGContextRestoreGState()? प्रलेखन पढ़ना, मुझे लगता है कि राज्य संदर्भ के लिए आंतरिक है, और पूरे संदर्भ को किसी भी तरह से फेंक दिया जाता है। –
क्या आप CGContextBeginPath() और CGContextClosePath() को कॉल करना आवश्यक है? मैंने पाया है कि मैं सिर्फ एक रास्ता बना सकता हूं और CGContextAddPath() को कॉल कर सकता हूं और चीजें ठीक काम करती हैं। साथ ही, CGContextClosePath() के लिए दस्तावेज़ कहते हैं कि "जब आप खुले पथ को भरते या क्लिप करते हैं, तो क्वार्ट्ज आपके लिए सबपैथ को बंद कर देता है", यह सुझाव देते हुए कि इसे स्वयं बंद करने की आवश्यकता नहीं है। – camdez