Re: Programatically creating/saving an NSImage;
Re: Programatically creating/saving an NSImage;
- Subject: Re: Programatically creating/saving an NSImage;
- From: Matt Budd (Madentec) <email@hidden>
- Date: Tue, 22 Mar 2005 09:05:11 -0700
Hey Shawn,
I tried supplying values to a dictionary, but still no help. The
representation it returns is an NSCachedImageRep. And there is still
only 1 imagerep in the image's representations array, so I don't think
it would matter what I passed to that -bestRepresentationForDevice:
since it only has one to choose from. Here is the modified example:
-----------------------------------------------
float lfWidth = 25;
float lfHeight = 50;
NSImage *loTestImage = [[NSImage alloc] initWithSize:
NSMakeSize(lfWidth, lfHeight)];
[loTestImage lockFocus];
//Here I would do more complicated NSBezierPath stuff
[[NSColor redColor] set];
NSRectFill(NSMakeRect(0, 0, lfWidth, lfHeight));
[loTestImage unlockFocus];
NSMutableDictionary *loDeviceDict = [NSMutableDictionary dictionary];
[loDeviceDict setValue: [NSValue valueWithSize: NSMakeSize(lfWidth,
lfHeight)] forKey: NSDeviceResolution];
[loDeviceDict setValue: NSDeviceRGBColorSpace forKey:
NSDeviceColorSpaceName];
[loDeviceDict setValue: [NSNumber numberWithInt: 8] forKey:
NSDeviceBitsPerSample];
[loDeviceDict setValue: [NSNumber numberWithBool: YES] forKey:
NSDeviceIsScreen];
[loDeviceDict setValue: [NSNumber numberWithBool: NO] forKey:
NSDeviceIsPrinter];
[loDeviceDict setValue: [NSValue valueWithSize: NSMakeSize(lfWidth,
lfHeight)] forKey: NSDeviceSize];
NSLog(@"%@", [[loTestImage bestRepresentationForDevice: loDeviceDict]
class]); //prints: "NSCachedImageRep"
NSLog(@"repcount: %d", [[loTestImage representations] count]);
//prints: "repcount: 1"
[loTestImage release];
-----------------------------------------------
- Matt
On Mar 21, 2005, at 4:15 PM, Shawn Erickson wrote:
On Mar 21, 2005, at 2:51 PM, Matt Budd (Madentec) wrote:
If I don't create the NSBitmapImageRep, the NSImage only has 1
representation, a NSCachedImageRep, of which I can get its pixel info
(through a -bitmapData message or something similar). If I use
-bestRepresentationForDevice:, it returns the only representation,
that NSCachedImageRep.
Did you try setting any of the following in the dictionary you supply
to -bestRepresentationForDevice:?
APPKIT_EXTERN NSString *NSDeviceResolution; /* NSValue containing
NSSize, basically dpi */
APPKIT_EXTERN NSString *NSDeviceColorSpaceName; /* NSString */
APPKIT_EXTERN NSString *NSDeviceBitsPerSample; /* NSValue containing
int */
APPKIT_EXTERN NSString *NSDeviceIsScreen; /* "YES" or not there */
APPKIT_EXTERN NSString *NSDeviceIsPrinter; /* "YES" or not there */
APPKIT_EXTERN NSString *NSDeviceSize; /* NSValue containing NSSize */
-Shawn
_______________________________________________
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