• 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
NSBitMapImageRep Woes
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

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


  • Follow-Ups:
    • Re: NSBitMapImageRep Woes
      • From: Graham Cox <email@hidden>
    • Re: NSBitMapImageRep Woes
      • From: "Henry McGilton (Boulevardier)" <email@hidden>
    • Re: NSBitMapImageRep Woes
      • From: Ken Thomases <email@hidden>
    • Re: NSBitMapImageRep Woes
      • From: David Duncan <email@hidden>
  • Prev by Date: Re: How to enforce a single NSDocument ... or should I do something else?
  • Next by Date: Re: NSBitMapImageRep Woes
  • Previous by thread: Re: NSXMLParser question about duplicate nodes
  • Next by thread: Re: NSBitMapImageRep Woes
  • Index(es):
    • Date
    • Thread