Become a MacRumors Supporter for $50/year with no ads, ability to filter front page stories, and private forums.

fernandovalente

macrumors 6502
Original poster
With a NSImage, I would set the window background this way:
Code:
[window setBackgroundColor:[NSColor colorWithPatternImage:img]]
I have an NSPDFImageRep which I would like to set as the background color. How may I do that?

Thanks in advanced!
 
Use the same NSColor method. Simply create an NSImage of the appropriate size and add the image rep you have to it.

All I get is a window with a black image. Also, the application crashes. I tried this:

Code:
NSImage *img = [[NSImage alloc] initWithSize:[rep size]];
[img addRepresentation:rep];
[window setBackgroundColor:[NSColor colorWithPatternImage:img]];
 
All I get is a window with a black image. Also, the application crashes. I tried this:

Code:
NSImage *img = [[NSImage alloc] initWithSize:[rep size]];
[img addRepresentation:rep];
[window setBackgroundColor:[NSColor colorWithPatternImage:img]];

Ouch! So there may be some undocumented issue using that sort of image rep then. How about you create the image, add a blank NSBitmapImageRep of the correct size etc, lock focus onto that and render the PDF rep into it?
 
All I get is a window with a black image. Also, the application crashes. I tried this:

Code:
NSImage *img = [[NSImage alloc] initWithSize:[rep size]];
[img addRepresentation:rep];
[window setBackgroundColor:[NSColor colorWithPatternImage:img]];

Can you post your compete code? If it's crashing I would imagine something else is going on.
 
Thank you guys. Found what was making my application crash.

I still have a problem. The window background is just black, not what I want it to be.

I'm using CGSPrivate and I would like to resize the window after the transition, and that's the only workaround I found.

This is the entire code I'm using to set the background image(I removed everything else from the function):

NSPDFImageRep *rep = [NSPDFImageRep imageRepWithData:[window dataWithEPSInsideRect:[window frame]]];
NSImage *img = [[NSImage alloc] init];
[img addRepresentation:rep];
[window setBackgroundColor:[NSColor colorWithPatternImage:img]];
 
I found the mistake I made
Code:
NSPDFImageRep *rep = [NSPDFImageRep imageRepWithData:[window dataWithPDFInsideRect:[window frame]]];
	NSImage *img = [[NSImage alloc] init];
	[img addRepresentation:rep];
	[window setBackgroundColor:[NSColor colorWithPatternImage:img]];
Anyway, as the screenshot doesn't have the same size of the window(as the window will be resized), the rest of the window gets black.
 
Register on MacRumors! This sidebar will go away, and you'll see fewer ads.