• 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
Creating a NSBitmapImageRep
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Creating a NSBitmapImageRep


  • Subject: Creating a NSBitmapImageRep
  • From: Richard Schreyer <email@hidden>
  • Date: Tue, 2 Jul 2002 23:24:04 -0700

I'm trying to create a NSBitmapImageRep with the following bit of code:

NSImage* image = [[NSImage alloc] initWithSize: size];
NSBitmapImageRep* bitmap = [[NSBitmapImageRep alloc]
initWithBitmapDataPlanes: nil
pixelsWide: size.width pixelsHigh: size.height
bitsPerSample: 8 samplesPerPixel: 4
hasAlpha: YES isPlanar: NO
colorSpaceName: NSCalibratedRGBColorSpace
bytesPerRow: 0 bitsPerPixel: 32];
unsigned char* imageBytes = [bitmap bitmapData];
int x, y;

[image addRepresentation: bitmap];

for (y = size.height-1; y >= 0; y--) {
for (x = size.width-1; x >= 0; x--) {
int pixIndex = 4 * (y*(int)size.width+x);
imageBytes[pixIndex] = 0; // red
imageBytes[pixIndex+1] = 0; // green
imageBytes[pixIndex+2] = 255; // blue
imageBytes[pixIndex+3] = 128; // alpha
}
}

Right now, I would just like to be able to create an image of a transparent color. Once that works, I'm going to vary the alpha to create a gradient. This is based on some code I found in the list archives.

The problem is the image isn't getting created correctly. If I give it an alpha of 255, everything works, and I get the desired color. If I set the alpha to 254, and then display the image, it draws black lines across the color in-line with the white portions of the pinstripes behind it. If I set the alpha to 253 or lower, I end up with transparent gray, it's transparency varying with the alpha.

Does anyone know what might be causing this?

Richard Schreyer
_______________________________________________
cocoa-dev mailing list | email@hidden
Help/Unsubscribe/Archives: http://www.lists.apple.com/mailman/listinfo/cocoa-dev
Do not post admin requests to the list. They will be ignored.

  • Follow-Ups:
    • Re: Creating a NSBitmapImageRep
      • From: Dave Hayden <email@hidden>
  • Prev by Date: Re: Installing a new login item?
  • Next by Date: Re: Creating a NSBitmapImageRep
  • Previous by thread: Re: Determining user log off
  • Next by thread: Re: Creating a NSBitmapImageRep
  • Index(es):
    • Date
    • Thread