Hi folks,

I'm implementing a crossplatform (not-only GUI) library, where everything is
drawn internally to an RGBA bitmap and then just copied to screen. On
Windows it works like charm especially since there is a support for
"in-memory" bitmaps. But I don't see such a feature on Mac. I ended up with
this code:

CGColorSpaceRef colorSpace =
CGColorSpaceCreateWithName(kCGColorSpaceGenericRGB);
        CGContextRef bmpcontext =
CGBitmapContextCreate((void*)desc.Bitmap.GetData(),
                                                        sz.X, sz.Y, 8, sz.X
* 4, colorSpace, kCGImageAlphaNoneSkipLast);
        CGColorSpaceRelease(colorSpace);

        CGContextSaveGState(context);
        CGRect cliprect = { r.X1, sz.Y - r.Y2, r.GetWidth(), r.GetHeight()
};
        CGContextClipToRect (context, cliprect);
        CGContextSetShouldAntialias (context, false);

        HIRect bounds;
        bounds.origin.x = 0;
        bounds.origin.y = 0;
        bounds.size.width = sz.X;
        bounds.size.height = sz.Y;

        CGImageRef temp = CGBitmapContextCreateImage (bmpcontext);
        CGContextDrawImage(context, bounds, temp);

        CGImageRelease(temp);
        CGContextRelease (bmpcontext);

        CGContextRestoreGState (context);


It basically converts the whole bitmap into CGImageRef and then copies a
part of it into the NSView's context. But it's quite slow. Is there a better
way to do this? And is there a way to create the in-memory images like they
are on Windows?

One more thing - I do the same thing in Carbon (I just need Cocoa because of
x64...) and I noticed that the coordinates for the CGContext is inverted
vertically, is that correct?? I mean the same context object type, but
different Y handling...

Thanks in advance.
Vojtech
_______________________________________________

Cocoa-dev mailing list (Cocoa-dev@lists.apple.com)

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:
http://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com

This email sent to arch...@mail-archive.com

Reply via email to