• 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 black and white image
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

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


  • Follow-Ups:
    • Re: Creating black and white image
      • From: Clark Cox <email@hidden>
    • Re: Creating black and white image
      • From: Chuck Soper <email@hidden>
  • Prev by Date: Re: Renaming files?
  • Next by Date: Re: Creating black and white image
  • Previous by thread: Re: NSImage very strange
  • Next by thread: Re: Creating black and white image
  • Index(es):
    • Date
    • Thread