Note that there are some explanatory texts on larger screens.

plurals
  1. POUIImage with border. Invalid Context 0x0
    primarykey
    data
    text
    <p>I'm fetching an image and saving it to temporary directory in a background thread. Before saving, I want to add a little white border to this UIImage. I'm doing this:</p> <pre><code> - (UIImage *)imageWithBorder:(UIImage *)image { CGSize newSize = CGSizeMake(image.size.width, image.size.height); CGRect rect = CGRectMake(0.0, 0.0, image.size.width, image.size.height); UIGraphicsBeginImageContextWithOptions(newSize, NO, image.scale); { CGContextRef context = UIGraphicsGetCurrentContext(); CGContextBeginTransparencyLayer (context, NULL); //Draw [image drawInRect:rect blendMode:kCGBlendModeNormal alpha:1.0]; CGContextSetRGBStrokeColor(context, 1.0, 1.0, 1.0, 1.0); CGContextStrokeRectWithWidth(context, rect, 10); CGContextEndTransparencyLayer(context); } UIImage *result = UIGraphicsGetImageFromCurrentImageContext(); UIGraphicsEndImageContext(); return result; } </code></pre> <p>Everything is okay, after loading that image from a temporary directory I can see border on an image, but in console I'm getting <code>invalid context 0x0</code> when the code below implements. What's wrong here?</p> <hr> <p><strong>Update 01</strong></p> <pre><code>- (UIImage *)imageWithBorder:(UIImage *)image { CGSize newSize = CGSizeMake(image.size.width, image.size.height); CGRect rect = CGRectMake(0.0, 0.0, image.size.width, image.size.height); UIGraphicsBeginImageContextWithOptions(newSize, NO, image.scale); { CGContextRef context = UIGraphicsGetCurrentContext(); CGContextDrawImage (context, rect, [image CGImage]); CGContextSetRGBStrokeColor(context, 1.0, 1.0, 1.0, 1.0); CGContextStrokeRectWithWidth(context, rect, 10); } UIImage *result = UIGraphicsGetImageFromCurrentImageContext(); UIGraphicsEndImageContext(); return result; } </code></pre>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload