I'm creating a pdf by hand and need to render a few images within a view. The images have their frames defined in a template nib file. However, I cannot seem to find a good way to render these images according to the frames that were assigned to them in the template file.
When I call
[imageView.layer renderInContext:pdfContext];
The view gets rendered with origin at 0,0.
UPDATE: The solution was to translate the origin of the coordinate system before rendering the context, and restore it after rendering
CGContextTranslateCTM(pdfContext, imageView.frame.origin.x,imageView.frame.origin.y);
//render the container, with the correct coordinate system
[v.layer renderInContext:pdfContext];
CGContextTranslateCTM(pdfContext, -imageView.frame.origin.x,-imageView.frame.origin.y);
How can I properly render a layer in graphics context with the correct origin, as defined within the view's frame.origin point?
I needed to adjust the coordinate system before the operation
CGContextTranslateCTM(pdfContext, imageView.frame.origin.x,imageView.frame.origin.y);
//render the container, with the correct coordinate system
[v.layer renderInContext:pdfContext];
CGContextTranslateCTM(pdfContext, -imageView.frame.origin.x,-imageView.frame.origin.y);
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With