• 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
Re: drawing into NSBitmapImageRep [SOLVED]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: drawing into NSBitmapImageRep [SOLVED]


  • Subject: Re: drawing into NSBitmapImageRep [SOLVED]
  • From: Chris Meyer <email@hidden>
  • Date: Tue, 18 Feb 2003 21:10:47 -0800

I've solved my particular problem by using CoreGraphics capabilities. My application required copying an arbitrary NSBitmapImageRep to another NSBitmapImageRep with a specific pixel format.

I followed these steps:

1 - create a destination NSBitmapImageRep with the desired pixel format
2 - create a CGContext with CGBitmapContextCreate, using the data from the destination NSBitmapImageRep
3 - create a CGImage with CGImageCreate, using data from the source NSBitmapImageRep
4 - copy the bitmap using CGContextDrawImage

The main difficulty is in mapping the source bitmap characteristics to the CGImage (specifically, the color space).

On Tuesday, February 18, 2003, at 12:30 PM, Chris Meyer wrote:

Can someone explain why the code below doesn't work as expected (i.e.
draw the orange rectangle into the bitmap)?

Is there any way to draw into a bitmap such that the bitmap has a
specific format pixel format?

The code:

NSImage *temp_image = [[[NSImage alloc]
initWithSize:NSMakeSize(200,200)] autorelease];

NSBitmapImageRep *bitmap_rep = [[[NSBitmapImageRep alloc]
initWithBitmapDataPlanes:NULL
pixelsWide:200
pixelsHigh:200
bitsPerSample:8
samplesPerPixel:3
hasAlpha:NO
isPlanar:NO
colorSpaceName:NSCalibratedRGBColorSpace
bytesPerRow:NULL
bitsPerPixel:NULL] autorelease];

[temp_image addRepresentation:bitmap_rep];

[temp_image setDataRetained:YES];

[temp_image lockFocus];
NSEraseRect( NSMakeRect(0,0,200,200) );
[[NSColor orangeColor] set];
NSFrameRectWithWidth( NSMakeRect(50,50,100,100), 10 );
[temp_image unlockFocus];
_______________________________________________
cocoa-dev mailing list | email@hidden
Help/Unsubscribe/Archives: http://www.lists.apple.com/mailman/listinfo/cocoa-dev
Do not post admin requests to the list. They will be ignored.
_______________________________________________
cocoa-dev mailing list | email@hidden
Help/Unsubscribe/Archives: http://www.lists.apple.com/mailman/listinfo/cocoa-dev
Do not post admin requests to the list. They will be ignored.

References: 
 >drawing into NSBitmapImageRep (From: Chris Meyer <email@hidden>)

  • Prev by Date: simple event question
  • Next by Date: Re: simple event question
  • Previous by thread: Re: drawing into NSBitmapImageRep
  • Next by thread: Invalid window error for a status bar item popup
  • Index(es):
    • Date
    • Thread