On Jan 6, 2010, at 9:21 AM, David Blanton wrote:
> 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];
> }
Two questions:
1. where is m_frameRect initialised ?
2. and are the width and height initialised to the precise number of bits
per row and number of rows
of whatever m_ptrs[0] is pointing at ?
3. (I said previously I can't count), are there potential endian issues
involved ?
>
> - (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!
>
=================================================
iPhone App Development and Developer Education . . .
Visit www.nonatomic-retain.com
Mac OSX Application Development, Plus a Great Deal More . . .
Visit www.trilithon.com
_______________________________________________
Cocoa-dev mailing list ([email protected])
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 [email protected]