• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
How to draw text to bitmap (array) with pre 10.5 libs
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

How to draw text to bitmap (array) with pre 10.5 libs


  • Subject: How to draw text to bitmap (array) with pre 10.5 libs
  • From: Glenn McCord <email@hidden>
  • Date: Mon, 30 Nov 2009 16:44:38 +1300

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

  • Follow-Ups:
    • Re: How to draw text to bitmap (array) with pre 10.5 libs
      • From: Graham Cox <email@hidden>
  • Prev by Date: troubles with tableview
  • Next by Date: Re: troubles with tableview
  • Previous by thread: Re: troubles with tableview
  • Next by thread: Re: How to draw text to bitmap (array) with pre 10.5 libs
  • Index(es):
    • Date
    • Thread