OK.

So, from other comments I made some changes.

1. Correctly set the dimensions by using m_bitmap.m_pixelsx and m_bitmap.m_pixelsy (these are members of our portable bitmap class).


        m_NSBitmapImageRep = [[NSBitmapImageRep alloc]
                                                  
initWithBitmapDataPlanes:m_ptrs
                                                  pixelsWide:m_bitmap.m_pixelsx
                                                  pixelsHigh:m_bitmap.m_pixelsy
                                                  bitsPerSample:8
                                                  samplesPerPixel:4
                                                  hasAlpha:YES
                                                  isPlanar:NO
                                                  
colorSpaceName:NSCalibratedRGBColorSpace
                                                  
bitmapFormat:NSAlphaFirstBitmapFormat
                                                  bytesPerRow:(4 * 
m_bitmap.m_pixelsx)
                                                  bitsPerPixel:32];


And changed the drawInRect to draw in the views bounds

- (void)drawRect:(NSRect)dirtyRect {
                
        NSRect bounds = [self bounds];
        [NSGraphicsContext saveGraphicsState];  
        [m_NSBitmapImageRep drawInRect:bounds];         
        [NSGraphicsContext restoreGraphicsState];
}

Now, from David Duncan's comment.

My bitmap data does have alpha, i.e 4 samples per pixel ARGB. I thought kCGImageAlphaNoneSkipFirst says don't make an alpha plane, skip byte 1 and go to RED.

I am not sure how to specify this in the 'bitmapFormat' parameter.


On Jan 6, 2010, at 10:35 AM, David Duncan wrote:

On Jan 6, 2010, at 9:21 AM, David Blanton wrote:

        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];

This code creates a bitmap with alpha.

context = CGBitmapContextCreate (bitmap.m_array, bitmap.m_pixelsx, bitmap.m_pixelsy, 8, bitmap.m_pixelsx * 4, colorSpace, kCGImageAlphaNoneSkipFirst|kCGBitmapByteOrder32Host);

This code creates a bitmap without alpha.

The problem is I just see garbage, no image. Clearly I am doing something wrong with the NSBitMapImageRep but I have no idea what.


Hence garbage.
--
David Duncan
Apple DTS Animation and Printing




_______________________________________________

Cocoa-dev mailing list (Cocoa-dev@lists.apple.com)

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 arch...@mail-archive.com

Reply via email to