NSBitMapImageRep Woes
NSBitMapImageRep Woes
- Subject: NSBitMapImageRep Woes
- From: David Blanton <email@hidden>
- Date: Wed, 6 Jan 2010 10:21:14 -0700
Here is the code:
@interface MyDocumentView : NSView {
@public
NSBitmapImageRep* m_NSBitmapImageRep;
NSRect m_frameRect;
float m_sz;
BBitmap m_bitmap;
unsigned char* m_ptrs[1];
}
- (void)awakeFromNib {
m_ptrs[0] = (unsigned char*)&m_bitmap.m_array;
m_NSBitmapImageRep = [[NSBitmapImageRep alloc]
initWithBitmapDataPlanes:m_ptrs
pixelsWide:m_frameRect.size.width
pixelsHigh:m_frameRect.size.height
bitsPerSample:8
samplesPerPixel:4
hasAlpha:YES
isPlanar:NO
colorSpaceName:NSCalibratedRGBColorSpace
bitmapFormat:NSAlphaFirstBitmapFormat
bytesPerRow:(4 * m_frameRect.size.width)
bitsPerPixel:32];
}
- (void)drawRect:(NSRect)dirtyRect {
[NSGraphicsContext saveGraphicsState];
[m_NSBitmapImageRep drawInRect:dirtyRect];
[NSGraphicsContext restoreGraphicsState];
}
m_bitmap.m_array is created in readFromData:ofType:fromFile
I know it is correct because if I use this code I get proper results:
(in this case bitmap is a local var but is generated just m_bitmap is.
context = CGBitmapContextCreate (bitmap.m_array, bitmap.m_pixelsx,
bitmap.m_pixelsy, 8, bitmap.m_pixelsx * 4, colorSpace,
kCGImageAlphaNoneSkipFirst|kCGBitmapByteOrder32Host);
CGImageRelease(_cgImageRef);
_cgImageRef = CGBitmapContextCreateImage (context);
CGImageRetain(_cgImageRef);
CGContextRelease(context);
CGColorSpaceRelease(colorSpace);
The problem is I just see garbage, no image. Clearly I am doing
something wrong with the NSBitMapImageRep but I have no idea what.
Please comment!
db
_______________________________________________
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