• 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
Problems with drawing to an NSImage in a faceless app
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Problems with drawing to an NSImage in a faceless app


  • Subject: Problems with drawing to an NSImage in a faceless app
  • From: Andres Santiago Perez-Bergquist <email@hidden>
  • Date: Wed, 12 Feb 2003 18:10:58 -0500

Hi, I'm fairly new to Cocoa, and can't figure out how to get this to work. I want to write a simple command-line tool for taking in several images and compositing them into a single image (to be used as part of a pipeline for generating dynamic web content). I figured I might as well do it in Cocoa (since my web server is running Mac OS X) and save myself the trouble of trying to parse file formats and all. To get NSImage, I had to add AppKit to my Foundation tool. When I go to run it, it complains about my attempt to lockFocus on the destination NSImage. I suspect the answer lies with NSImageRep, but I'm not sure how... Error message and source follow:

----

kCGErrorInvalidConnection : CGSNewWindow: Invalid connection
2003-02-12 18:03:39.216 imagecomposite[9797] _NXCreateWindow: error creating window (1002)
kCGErrorInvalidConnection : CGSSetWindowDepth: Invalid connection
kCGErrorInvalidConnection : CGSSetWindowAutofill: Invalid connection
kCGErrorInvalidConnection : CGSSetWindowOpacity: Invalid connection
kCGErrorInvalidConnection : CGSGetWindowType: Invalid connection
kCGErrorIllegalArgument : CGSLockWindowRectBits: Invalid window
kCGErrorFailure : Failed to create window context device.
kCGErrorFailure : CGWindowContextCreate: failed to create context.
2003-02-12 18:03:39.461 imagecomposite[9797] _initWithWindowNumber: error creating graphics ctxt object for ctxt:0, window:-1
kCGErrorFailure : CGContextResetClip: invalid context
kCGErrorFailure : CGContextReplaceTopGState: invalid context
2003-02-12 18:03:39.466 imagecomposite[9797] *** Assertion failure in -[NSView lockFocus], AppKit.subproj/NSView.m:2343
2003-02-12 18:03:39.467 imagecomposite[9797] *** Uncaught exception: <NSInternalInconsistencyException> lockFocus sent to a view whose window is deferred and does not yet have a corresponding platform window
Trace/BPT trap

----

#import <Foundation/Foundation.h>
#import <AppKit/AppKit.h>
#import <stdlib.h>

int main (int argc, const char * argv[])
{
NSAutoreleasePool * pool = [[NSAutoreleasePool alloc] init];

if (argc < 3)
{
exit(1);
}

int width = strtol(argv[1], NULL, 10);
int height = strtol(argv[2], NULL, 10);

NSImage *theImage = [[NSImage alloc] initWithSize:NSMakeSize(width, height)];
[theImage lockFocus];

for (int i = 3; i < argc; i++)
{
int x = strtol(argv[i++], NULL, 10);
int y = strtol(argv[i++], NULL, 10);
NSImage *currentImage = [[NSImage alloc] initWithContentsOfFile:[NSString stringWithCString:(argv[i])]];

[currentImage compositeToPoint:NSMakePoint(x, y) operation:NSCompositeSourceAtop];

[currentImage release];
}

[theImage unlockFocus];

NSData *imageData = [theImage TIFFRepresentation];
[imageData writeToFile:@"/dev/stdout" atomically:NO];

[pool release];
return 0;
}
_______________________________________________
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.

  • Prev by Date: layout management and cocoa
  • Next by Date: Monitoring the selection in an NSOutlineView
  • Previous by thread: Re: layout management and cocoa
  • Next by thread: Monitoring the selection in an NSOutlineView
  • Index(es):
    • Date
    • Thread