|[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]|
Hi. I've been hunting around trying to find a way of drawing text to context so that I can then retrieve the image data as an array of bytes. I would like to support OSX 10.4, so my original (working code) won't do. Unfortunately though, I'm getting zeros for data, probably from totally misinterpreting how to use the libs. I currently have. unsigned char* bitmapData = new unsigned char[width * height * depth]; memset(bitmapData, 0, width*height*data); NSBitmapImageRep* rep = [[[NSBitmapImageRep alloc] initWithBitmapDataPlanes:&bitmapData // Single plane; just our bitmapData pixelsWide:width pixelsHigh:height bitsPerSample:8 samplesPerPixel:4 // ARGB hasAlpha:YES isPlanar:NO colorSpaceName:NSCalibratedRGBColorSpace bytesPerRow:0 // Let it compute bytesPerRow and bitsPerPixel bitsPerPixel:0] autorelease]; [NSGraphicsContext saveGraphicsState]; NSGraphicsContext* context = [NSGraphicsContext graphicsContextWithBitmapImageRep:rep]; [NSGraphicsContext setCurrentContext:context]; NSPoint point; point.x = 0; point.y = 0; [nsString drawAtPoint:point withAttributes:nsAttributes]; [NSGraphicsContext restoreGraphicsState]; unsigned char *returnData = [rep bitmapData]; What I'm expecting is the drawAtPoint method to draw nsString inside the bitmapRep of the NSContext at which point I can retrieve the raw data and do something with it. On account of the data all being zero, I'm obviously doing something wrong and would really appreciate some advice. Cheers. _______________________________________________ Cocoa-dev mailing list (email@hidden) 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: This email sent to email@hidden
Visit the Apple Store online or at retail locations.
Copyright © 2011 Apple Inc. All rights reserved.