Hi Gerriet,

On Aug 18, 2013, at 17:16 , Gerriet M. Denkmann <[email protected]> wrote:

>> [Tom Davie]
>> Uhh sorry, my bad, I meant CG*Bitmap*ContextCreate…
>> 
>> http://developer.apple.com/library/ios/documentation/graphicsimaging/Reference/CGBitmapContext/Reference/reference.html
> 
> Ah, now I found lots of info!
> 
> But I do not understand it. CIImage, CGImage, NSImage, UIImage... This is 
> just too much for my small brain.
[…]
> NSImage *image = [[NSImage alloc] initWithCGImage: cgImage size: NSZeroSize 
> ]; 
> (ignoring leaks for the time being)
> ... and then continued with my old code.
> 
> The png is still 100 pixels wide.

I think the problem may be that you are keeping the NSImage.  NSImage is 
specifically made to deal with images (icons in particular) that you want to 
display on screen, and my reading of the docs and various forums suggest that 
NSImage may be doing the doubling for you to be “helpful” (for example:  it may 
be caching your original size image into a representation for the screen, which 
will have twice the pixels on a Retina display, and then using the “best” 
representation later on when you want to save, which will be the pixel-doubled 
one).

If you want control over what is happening, my experience is that it's best to 
avoid NSImage and stick to something like NSBitmapImageRep, for example:

        NSBitmapImageRep *image = [[[NSBitmapImageRep alloc] 
initWithCGImage:cgImage] autorelease];
        […]

Now if all that CG low-level stuff seems a bit verbose, you might want to try 
MPWDrawingContext:

        bitmapContext = [MPWCGDrawingContext rgbBitmapContext:NSMakeSize( 50, 
50 )];
        [… drawing code here …]
        image = [bitmapContext image];    // UIImage on iOS, NSBitmapImageRep 
on OSX  

On Github:  https://github.com/mpw/MPWDrawingContext

Cheers,

Marcel


_______________________________________________

Cocoa-dev mailing list ([email protected])

Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com

Help/Unsubscribe/Update your Subscription:
https://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com

This email sent to [email protected]

Reply via email to