• 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
How to render 8-bit bitmap image representation?
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

How to render 8-bit bitmap image representation?


  • Subject: How to render 8-bit bitmap image representation?
  • From: Tron Thomas <email@hidden>
  • Date: Sun, 24 Jun 2007 12:27:04 -0700

I created an 8-bit grayscale bitmap image using code like the following:

    NSSize size = { 128.0f, 128.0f };
    image = [[NSImage alloc] initWithSize:size];

NSBitmapImageRep* bitmap =
[[NSBitmapImageRep alloc] initWithBitmapDataPlanes:NULL
pixelsWide:size.width pixelsHigh:size.height bitsPerSample:8
samplesPerPixel:1 hasAlpha:NO isPlanar:NO
colorSpaceName:NSCalibratedWhiteColorSpace bytesPerRow:0
bitsPerPixel:8];


    [image addRepresentation:bitmap];


Later on I did something like:

    [image lockFocus];

    // Do some drawing…

    [image unlockFocus];

When the rendering to the image was done, I then wanted to access the bitmap data. So, I tried doing something such as:

    NSBitmapImageRep* bitmap =
        [[image representations] objectAtIndex:0];
    unsigned char* data = [bitmap bitmapData];

This didn't work because, it turns out that locking the image for rendering causes the image to throw away its current representation and create an NSCachedImageRep instead. NSCachedImageRep doesn't support calling bitmapData to access the bits in the image.

I found I could get a bitmap representation of the image by doing:

    NSBitmapImageRep* bitmap =
        [NSBitmapImageRep imageRepWithData:[image TIFFRepresentation]];

However, when I do this the image representation is 24-bit instead of the 8-bit format I wanted originally.

How can I get a rendering for a bitmap image representation that has the 8-bit pixel format I want?

_______________________________________________

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: How to render 8-bit bitmap image representation?
      • From: "Ken Ferry" <email@hidden>
    • Re: How to render 8-bit bitmap image representation?
      • From: David Duncan <email@hidden>
  • Prev by Date: Re: ObjC 3D engine
  • Next by Date: Re: Unselectable NSTableView with selectable cell controls
  • Previous by thread: Re: [SOLVED] NSScrollView: General Question When does scrollRectToVisible does not scroll?
  • Next by thread: Re: How to render 8-bit bitmap image representation?
  • Index(es):
    • Date
    • Thread