Re: Creating an NSImage from a bitmap
Re: Creating an NSImage from a bitmap
- Subject: Re: Creating an NSImage from a bitmap
- From: Hidetomo Katsura <email@hidden>
- Date: Thu, 10 Aug 2006 13:01:02 -0700
btw, there is a leak in my sample code (glyph also needs to be
released or autoreleased). sorry about that.
regards,
katsura
On Aug 10, 2006, at 12:45 PM, Craig Dooley wrote:
Actually, to correct myself, I don't need to flip the alpha. I was
compositing it incorrectly. Thanks for the help.
-Craig
On 8/10/06, Hidetomo Katsura <email@hidden> wrote:
make sure to let the mailing list know that it worked. :)
regards,
katsura
On Aug 10, 2006, at 12:17 PM, Craig Dooley wrote:
> You're right. I think I got it working by flipping the alpha, and
> using NSCompositeDestinationAtop. I don't know where I got that
from,
> but that's for fixing that for me.
>
> -Craig
>
> On 8/10/06, Hidetomo Katsura <email@hidden> wrote:
>> you are welcome. fyi, it works with the same pattern for both
black
>> and alpha. i forgot to mention that you need to use
>> NSCompositeSourceOver (not NSCompositeCopy) to draw the image
if you
>> want to use alpha.
>>
>> regards,
>> katsura
>>
>> On Aug 10, 2006, at 11:39 AM, Craig Dooley wrote:
>>
>> > Thanks guys. That works if I copy the pattern and bitswap it
>> for the
>> > alpha channel.
>> >
>> > On 8/10/06, Hidetomo Katsura <email@hidden> wrote:
>> >> Craig,
>> >>
>> >> this seems to work. you need to use an alpha plane and
>> hasAlpha:YES
>> >> if you want a transparent center.
>> >>
>> >> - (NSImage *)black16x16SquareImage
>> >> {
>> >> static unsigned char pattern[] =
>> >> {
>> >> 0xff, 0xff,
>> >> 0xff, 0xff,
>> >> 0xc0, 0x03,
>> >> 0xc0, 0x03,
>> >> 0xc0, 0x03,
>> >> 0xc0, 0x03,
>> >> 0xc0, 0x03,
>> >> 0xc0, 0x03,
>> >> 0xc0, 0x03,
>> >> 0xc0, 0x03,
>> >> 0xc0, 0x03,
>> >> 0xc0, 0x03,
>> >> 0xc0, 0x03,
>> >> 0xc0, 0x03,
>> >> 0xff, 0xff,
>> >> 0xff, 0xff
>> >> };
>> >>
>> >> NSBitmapImageRep *glyph;
>> >> NSImage *image;
>> >> unsigned char *planes[ 2 ];
>> >>
>> >> planes[ 0 ] = pattern; // black
>> >> planes[ 1 ] = pattern; // alpha
>> >> glyph = [[NSBitmapImageRep alloc]
>> >> initWithBitmapDataPlanes:&planes[ 0 ]
>> >> pixelsWide:16
>> >> pixelsHigh:16
>> >> bitsPerSample:1
>> >> samplesPerPixel:2
>> >> hasAlpha:YES
>> >> isPlanar:YES
>> >>
>> >> colorSpaceName:NSDeviceBlackColorSpace
>> >> bytesPerRow:2
>> >> bitsPerPixel:0];
>> >> image = [[NSImage alloc] initWithSize:NSMakeSize( 16,
>> 16 )];
>> >> [image addRepresentation:glyph];
>> >>
>> >> return [image autorelease];
>> >> }
>> >>
>> >> regards,
>> >> katsura
>> >>
>> >> On Aug 10, 2006, at 9:01 AM, Craig Dooley wrote:
>> >>
>> >> > I am attempting to take a bitmap, and generate a black/
>> transparent
>> >> > NSImage from it. The following example is attempting to
draw a
>> >> 16x16
>> >> > square in black, that is transparent in the center. It does
>> >> create a
>> >> > 16x16 NSImage, which i can display, but only the top line and
>> one
>> >> > pixel on the second row are black, and the rest is white. Is
>> there
>> >> > any way to do this, or do i need to translate the data to
>> another
>> >> > format first?
>> >> >
>> >> > unsigned char pattern[] = {
>> >> > 0xff, 0xff,
>> >> > 0xff, 0xff,
>> >> > 0xc0, 0x03,
>> >> > 0xc0, 0x03,
>> >> > 0xc0, 0x03,
>> >> > 0xc0, 0x03,
>> >> > 0xc0, 0x03,
>> >> > 0xc0, 0x03,
>> >> > 0xc0, 0x03,
>> >> > 0xc0, 0x03,
>> >> > 0xc0, 0x03,
>> >> > 0xc0, 0x03,
>> >> > 0xc0, 0x03,
>> >> > 0xc0, 0x03,
>> >> > 0xff, 0xff,
>> >> > 0xff, 0xff
>> >> > };
>> >> >
>> >> > unsigned char *planes[] = {pattern};
>> >> > glyph = [[NSBitmapImageRep alloc]
>> initWithBitmapDataPlanes:planes
>> >> > pixelsWide:16
>> >> > pixelsHigh:16
>> >> > bitsPerSample:1
>> >> > samplesPerPixel:1
>> >> > hasAlpha:NO
>> >> > isPlanar:NO
>> >> > colorSpaceName:NSDeviceBlackColorSpace
>> >> > bytesPerRow:0
>> >> > bitsPerPixel:0];
>> >> > image = [[NSImage alloc] init];
>> >> > [image addRepresentation:glyph];
>> >> >
>> >> > -Craig
>> >>
>> >
>> >
>> > --
>> >
>>
---------------------------------------------------------------------
>> -
>> > -
>> > Craig Dooley <email@hidden>
>>
>>
>
>
> --
>
---------------------------------------------------------------------
-
> -
> Craig Dooley <email@hidden>
--
----------------------------------------------------------------------
-
Craig Dooley <email@hidden>
_______________________________________________
Do not post admin requests to the list. They will be ignored.
Cocoa-dev mailing list (email@hidden)
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden
_______________________________________________
Do not post admin requests to the list. They will be ignored.
Cocoa-dev mailing list (email@hidden)
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden