1

I need to use UIGraphicsRendererFormat for my UIGraphicsImageRenderer to change its scale but I can't find even one example online. This is my code, I appreciate any help:

//Based on documentation I know that I have to create an instance from
UIGraphicsImageRendererFormat and set its scale to my desired scale but how can I use it???

UIGraphicsImageRendererFormat * format = [UIGraphicsImageRendererFormat defaultFormat];
format.scale=1.0;
UIGraphicsImageRenderer*renderer = [[UIGraphicsImageRenderer alloc]initWithBounds:self.bgImageView.layer.bounds];

UIImage*image= [renderer imageWithActions:^(UIGraphicsImageRendererContext*_Nonnull myContext){
        [self.bgImageView.layer renderInContext: myContext.CGContext];
}];

Documentation : https://developer.apple.com/documentation/uikit/uigraphicsrendererformat?language=objc

Reza.Ab
  • 1,195
  • 1
  • 11
  • 21
  • Do you want to create image with some resolution form existing image? – Mangesh Murhe Feb 20 '18 at 04:33
  • Not in this case, I put two imageviews on top of eachother and set their frame and want to do this using uigraohicsimagerenderer which works great but i want to do it without caring about device scale, I want it to render always at scale 1 – Reza.Ab Feb 20 '18 at 09:33
  • _bgImageview.layer.mask = _fgimageview.layer; just a simple masking via uigraohicsimagerenderer because its faster this way and its just for preview and it works but I wsnt it to do it at scale one always. Documentation says its possible if i use uigraphicsimagerendererformat but i don't know how to!?! – Reza.Ab Feb 20 '18 at 09:42

1 Answers1

1

Using this API might fix your issue:

   UIGraphicsImageRendererFormat * format = [UIGraphicsImageRendererFormat defaultFormat];
   format.scale=1.0;
   UIGraphicsImageRenderer *renderer = [[UIGraphicsImageRenderer alloc] initWithSize:CGSizeMake(200, 200) format: format];

See this doc

sambro
  • 816
  • 5
  • 12