I need to save an NSImage as a TIFF file, as a 1-bit (black and white) image, 
and at a specific resolution (dpi). I have my NSImage being created in RGB 
mode, and I can save it (as RGB).
I've been trying to read the other posts on 1-bit images, but I don't 
understand things like "you'll have to fill it yourself".
(http://www.cocoabuilder.com/archive/cocoa/204408-1-bit-nsbitmapimagerep.html?q=%221+bit+image%22#204521)

Does anyone have some code they could share to take an NSImage and then make it 
1-bit?

Also, I have tried to use [nsImage setSize:NSMakeSize(fx, fy)] on an NSImage 
and it appears to work, but when I save the image then it defaults back to 
72dpi (the default). So is there something that I need to do to aside from 
setSize?

Here's what I am using for my saving method:

-(IBAction)saveImage:(id)sender
{
 IKSaveOptions *saveOptions = [[IKSaveOptions alloc]
       initWithImageProperties: NULL
       imageUTType: @"public.tiff"]; 
 
 NSSavePanel *savePanel = [NSSavePanel savePanel];
 
 [savePanel setAllowedFileTypes:[NSArray arrayWithObject:@"tif"]];
 [savePanel setTitle:@"Save QR Image As TIF"];
 [savePanel setMessage:@"TIF will be the file type of the image."];
 
 [savePanel beginWithCompletionHandler:^(NSInteger result)
 {
  if (result == NSFileHandlingPanelOKButton) 
  { 
   NSString *newUTType = [saveOptions imageUTType];
   NSURL *url = [savePanel URL];
      
   CGImageRef image = [qrImage CGImageForProposedRect:NULL context:NULL 
hints:NULL];
   
   if (image)
   {
    CGImageDestinationRef dest = CGImageDestinationCreateWithURL((CFURLRef)url,
                    (CFStringRef)newUTType, 1, NULL);
    if (dest)
    {
     CGImageDestinationAddImage(dest, image,
              (CFDictionaryRef)[saveOptions imageProperties]);
     CGImageDestinationFinalize(dest);
     CFRelease(dest);
    } //(dest)
   } //(image)
 //CALL ASOC FILE PLACER HERE  
  } //(result == NSFileHandlingPanelOKButton)
 } ]; //savePanel
}

Thanks,
Chris

_______________________________________________

Cocoa-dev mailing list (Cocoa-dev@lists.apple.com)

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:
https://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com

This email sent to arch...@mail-archive.com

Reply via email to