Hi Will
I believe the solution to both of these issues will be the same. You need to create a new bitmap in memory and render the image into it. You will have to drop down to Core Graphics (C) to get this done though but it's not too hard.
Something like this:
* Create an image with CGBitmapContextCreate of the size you want.
* Fill the image with white using CGContextSetFillColorWithColor and CGContextFillRect.
* Draw your image over the top with CGContextDrawImage.
* Create an image back from your context using CGBitmapContextCreateImage and - initWithCGImage:size: on NSImage.
* Don't forget to release all of your core foundation objects as ARC does not apply to core graphics/core foundation. See CGContextRelease, CGImageRelease, etc...
Hope this helps.
Dave
---
twitter: @daveverwer
mail:
dave....@shinydevelopment.com
web:
http://shinydevelopment.com
Shiny Development Ltd. is registered in England, Registration Number: 05805802. Registered Office: 4 Claridge Court, Lower Kings Road, Berkhamsted, Herts., HP4 2AF.
On Monday, 27 August 2012 at 18:16, Will Jessop wrote:
> Hi All,
>
> At work we've recently started to need to turn PDF files into images. We are using the gs (ghostscript) command and it was taking 40+ seconds to create an image of a large PDF. I figured Cocoa could do better so I wrote a PDF Imaging class. Here's the .h, .m and a main.m to drive it (uses ARC):
>
>
https://gist.github.com/e1473f229c3b86ec8499
>
> It works fine, though there are a couple of issues that are beyond my current cocoa abilities and could use some pointers.
>
> 1) When I create PNG files the background is transparent, I can't work out how to make it white, line 32 in the .m:
>
> NSData *imageData = [imageRep representationUsingType:NSPNGFileType properties:imageProps];
>
> 2) The image created has relatively small dimensions. I need to scale the PDF up before creating the image.
>
> I haven't worked out how to do either of these things so would appreciate some help from the more knowledgable here. Critique of my Obj-c code also welcome.
>
> Thanks in advance,
> Will.
>
>
>
> --
> You received this message because you are subscribed to the Google Groups "NSManchester - Cocoa Developers Meetup" group.
> To view this discussion on the web visit
https://groups.google.com/d/msg/nsmanchester/-/nM52-g4emwcJ.
> To post to this group, send email to
nsmanc...@googlegroups.com (mailto:
nsmanc...@googlegroups.com).
> To unsubscribe from this group, send email to
nsmanchester...@googlegroups.com (mailto:
nsmanchester...@googlegroups.com).
> For more options, visit this group at
http://groups.google.com/group/nsmanchester?hl=en.