Creating black and white image
Creating black and white image
- Subject: Creating black and white image
- From: Osamu Shigematsu <email@hidden>
- Date: Thu, 23 Dec 2004 03:02:51 +0900
Hello, all.
I'm trying to create black and white (bitmap) image with following
function to print an image to MW-100 USB printer from Brother
Industries.
I call this function with full color image (Created from color JPEG),
imageView (NSImageView) shows a color image.
Is there anyone who are able to explain the reason why?
Currently I use QuickTime (Graphics Importer) and QuickDraw function
and works well, though I would like to learn Cocoa framework.
Thank you very much for your advice.
- (void)bitmapWithImage:(NSImage *)src
{
NSSize size = [src size];
const int bitmapWidth = size.width;
const int bitmapHeight = size.height;
NSBitmapImageRep *rep = [[NSBitmapImageRep alloc]
initWithBitmapDataPlanes:nil
pixelsWide:bitmapWidth
pixelsHigh:bitmapHeight
bitsPerSample:1
samplesPerPixel:1
hasAlpha:NO
isPlanar:NO
colorSpaceName:@"NSCalibratedWhiteColorSpace"
bytesPerRow:(bitmapWidth + 7) / 8
bitsPerPixel:1];
NSImage *dst = [[[NSImage alloc]
initWithSize:NSMakeSize(bitmapWidth, bitmapHeight)]
autorelease];
[dst addRepresentation:rep];
[dst lockFocus];
[src compositeToPoint:NSMakePoint(0, 0)
operation:NSCompositeSourceOver
fraction:1];
[dst unlockFocus];
[imageView setImage:dst];
}
--
Osamu Shigematsu
_______________________________________________
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