On Dec 15, 2008, at 10:50 PM, David Duncan wrote:

On Dec 15, 2008, at 12:47 PM, Thomas Clement wrote:


Alright but how am I suppose to draw a part of the image without loading the whole image from disk first? Creating a NSBitmapImageRep requires creating a NSData with the whole image. I tried using CGBitmapContextCreate but I got a malloc error again when calling CGContextDrawImage (passing a small rect to draw).


If you use the bitmap context method, then you create a context that is the size of the image data that you want (so if you want a 20x20 section of the image, you create a 20x20 context) then draw the whole image to it. If you use ImageIO to load the image, then it will only load portion of the image required to draw that area. In order to get the correct part of the image, you would need to translate the context (via CGContextTranslateCTM for example) to position the image correctly.

That's right, I was not doing it correctly, this is now working.
Also I noticed I can call CGImageCreateWithImageInRect to create a new CGImage which is a smaller area of the original image and then call CGImageGetDataProvider and CGDataProviderCopyData to get the pixel data. Seem easier and faster too. However CGDataProviderCopyData is 10.5 minimum.


Thanks!
Thomas

_______________________________________________

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