Note that there are some explanatory texts on larger screens.

plurals
  1. POUIEdgeInsets ignored on CGContextDrawImage within a UIGraphicsBeginImageContextWithOptions
    primarykey
    data
    text
    <p>I am struggling getting Image Insets to work when drawing to an off screen buffer.</p> <p>Using the resizableImageWithCapInsets: on an UIImage directly setImage: into a button works fine for me:</p> <pre><code>UIImage * base = [UIImage imageNamed:@"button.png"]; UIImage * img = [base resizableImageWithCapInsets:UIEdgeInsetsMake(20,20,20,20)]; [self setImage:img forState:UIControlStateNormal]; </code></pre> <p>As shown below (left is raw scaling, right is scaled with insets):</p> <p><img src="https://i.stack.imgur.com/Vcau1.png" alt="Image stretched without ado"> <img src="https://i.stack.imgur.com/alfVc.png" alt="Image stretched with decent insets"></p> <p>So the right one is fine - the lines top/botton/left/right are equally spaced. So far so good.</p> <p>Now if I try the very same thing with an image that is drawn and then captured to an off screen buffer with:</p> <pre><code>UIImage * base = [UIImage imageNamed:@"button.png"]; base = [base resizableImageWithCapInsets:UIEdgeInsetsMake(20,20,20,20)]; UIGraphicsBeginImageContextWithOptions(self.bounds.size, NO, 0); ctx = UIGraphicsGetCurrentContext(); CGContextDrawImage(ctx, CGRectMake(0,0,self.bounds.size.width, self.bounds.size.height), [base CGImage]); img = UIGraphicsGetImageFromCurrentImageContext(); UIGraphicsEndImageContext(); [self setImage:img forState:UIControlStateNormal]; </code></pre> <p>I get below (again left is raw scaling, right is with insets):</p> <p><img src="https://i.stack.imgur.com/pUPAV.png" alt="raw scaling, side buffer"><img src="https://i.stack.imgur.com/u3Rgb.png" alt="scaling with inset, side buffer (WRONG!)">.</p> <p>So here it seems that the insets are ignored.</p> <p>Anyone any suggestions as to what is going wrong here ? Fully functional example at <a href="http://people.apache.org/~dirkx/insetSample.zip" rel="nofollow noreferrer">http://people.apache.org/~dirkx/insetSample.zip</a> and just the key code at <a href="http://pastebin.com/rm8h6YFV" rel="nofollow noreferrer">http://pastebin.com/rm8h6YFV</a>.</p> <p>Any and all suggestions appreciated.</p> <p>Dw</p>
    singulars
    1. This table or related slice is empty.
    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.
 

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