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

Senor Cuete

macrumors 6502
Original poster
Nov 9, 2011
423
30
I use an object to convert NSViews to NSImages like this
Code:
- (NSImage *) imageForView: (NSView *)aView{
    NSImage *image = [[[NSImage alloc] initWithData: [self PDFForView: aView]] autorelease];
    return image;
}
Then these can be converted to various file types like this:
Code:
- (NSData*) representationForFileType: (NSImage*) image fileType: (NSBitmapImageFileType) fileType 
{
    NSData *temp = [image TIFFRepresentation];
    NSBitmapImageRep *bitmap = [NSBitmapImageRep imageRepWithData: temp];
    NSData *imgData = [bitmap representationUsingType: fileType properties: @{}];
    return imgData;
}
Also you can convert an image to PDF like this:
Code:
dataForPboardType:image fileType: NSPasteboardTypePDF];
and to a CIImage like this
Code:
CIImage * cimg = [CIImage imageWithData: [image TIFFRepresentation]];
NSBitmapImageFileType is an enumerated type with the following constants:
NSBitmapImageFileTypeTIFF
NSBitmapImageFileTypeBMP
NSBitmapImageFileTypeGIF
NSBitmapImageFileTypeJPEG
NSBitmapImageFileTypePNG
NSBitmapImageFileTypeJPEG2000

Are any other image file types defined in Mac OS?
 

Senor Cuete

macrumors 6502
Original poster
Nov 9, 2011
423
30
My Mac OS project won't build with this constant and searching the developer documentation yields no results so I'm guessing that this isn't in Mac OS.
 

f54da

macrumors 6502
Dec 22, 2021
346
128
It's a private symbol. You asked for other graphics formats, and this is one of them. It's the format returned when you do "NSImage imageNamed". It's not a NSBitmapImageRep so you can't really do much with it. You can even create one from a cgimage if you want, but I'm not sure why you'd want to.

Code:
@interface NSCoreUIImageRep : NSImageRep {
    struct __CFDictionary { } * _coreUIImageOptions;
    NSAppearance * _preferredAppearance;
}

@property (atomic, readwrite, retain) NSAppearance *preferredAppearance;

+ (id)imageRepWithCGImage:(struct CGImage { }*)arg1;
+ (id)imageRepWithCGLayer:(struct CGLayer { }*)arg1;
+ (id)imageRepWithCocoaName:(id)arg1;

- (BOOL)_drawOnlyUsesOneDrawingOperation;
- (BOOL)_isValid;
- (BOOL)_wantsToBeCached;
- (void)addEffects:(id)arg1;
- (struct CGRect { struct CGPoint { double x_1_1_1; double x_1_1_2; } x1; struct CGSize { double x_2_1_1; double x_2_1_2; } x2; })boundingRectWithExtraEffects:(id)arg1;
- (struct CGRect { struct CGPoint { double x_1_1_1; double x_1_1_2; } x1; struct CGSize { double x_2_1_1; double x_2_1_2; } x2; })boundingRectWithExtraEffectsForState:(unsigned long long)arg1 backgroundStyle:(int)arg2 context:(id)arg3;
- (id)copyWithZone:(struct _NSZone { }*)arg1;
- (struct __CFDictionary { }*)coreUIDrawOptions;
- (void)dealloc;
- (id)description;
- (BOOL)draw;
- (void)encodeWithCoder:(id)arg1;
- (BOOL)hasEffects;
- (id)initWithCGImage:(struct CGImage { }*)arg1;
- (id)initWithCGLayer:(struct CGLayer { }*)arg1;
- (id)initWithCocoaName:(id)arg1;
- (id)initWithCoder:(id)arg1;
- (id)initWithCoreUIDrawOptions:(struct __CFDictionary { }*)arg1 size:(struct CGSize { double x1; double x2; })arg2;
- (BOOL)isTemplate;
- (id)preferredAppearance;
- (void)setBackgroundStyle:(int)arg1;
- (void)setPreferredAppearance:(id)arg1;
- (void)setState:(unsigned long long)arg1;
- (void)setSuppressesCache:(BOOL)arg1;
- (void)setTemplate:(BOOL)arg1;
- (unsigned long long)state;
- (BOOL)suppressesCache;

@end
 

Senor Cuete

macrumors 6502
Original poster
Nov 9, 2011
423
30
That's interesting. It lt looks like a subclass of NSImage with a bunch of stuff that you wouldn't use. Maybe the OS uses it. Also according to the developer documentation and also in my code [NSImage imageNamed] returns an NSImage that's in the app bundle.
 

f54da

macrumors 6502
Dec 22, 2021
346
128
Not necessarily in the app bundle, it's also used for prebaked appkit sprites, like up arrow, right arrow, etc.
 
Register on MacRumors! This sidebar will go away, and you'll see fewer ads.