0

What is the CoreGraphics equivalent of UIKit's contentScaleFactor?

I am creating a PDF using the UKit PDF creation functions, which allow rendering to a PDF context. I have a requirement, however, to DEGRADE the quality of the generated PDF. We have achieved this already (rendering to a UIView) using UIKit's contentScaleFactor property, which is the factor of conversion between graphics space and pixel space. However, I need to apply this magic & voodoo to a CGContextRef, without a UIView, but I don't know what I should do.

Any other suggestions as to how to degrade the PDF quality would be much appreciated.

Thanks

Edit: My input is a PDF document. I am re-creating a PDF from another PDF using CoreGraphics, but the process CAN be slow, depending on the graphical intensity of some PDF pages.

micksabox
  • 113
  • 6

1 Answers1

0

When you create you context, specify width and height that are a fraction of your original PDF:

    CGContextRef context = CGBitmapContextCreate(NULL, 
                                    pdfSize.width / 4, 
                                    pdfSize.height/4, 
                                    8,                      
                                    0,   
                                    colorSpace, 
                                    kCGImageAlphaPremultipliedLast | kCGBitmapByteOrder32Big);

then do your drawing here scaling it down as appropriate. Then you could do:

CGImageRef cgImage = CGBitmapContextCreateImage(ctx);
UIImage *reflectionImage = [UIImage imageWithCGImage:cgImage scale:4.0 orientation:up];

or you could draw cgImage image in a new enlarged context, it depends on what you are trying to do.

sergio
  • 68,819
  • 11
  • 102
  • 123
  • The problem I have is I am drawing a PDF into another PDF (basically, recreating it in CoreGraphics). So in other words, a PDF is my input; not an image. – micksabox Mar 05 '13 at 18:19
  • You mentioned `CGContext`, so I thought you were using `CGContextDrawPDFPage` to create an image from a pdf page... once you have a bitmap representation of your page, you can create a new PDF... maybe you could clarify a bit what/how you are trying to do exactly – sergio Mar 05 '13 at 18:25