Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>@Julius: Your code is way too complicated and contains several bugs. I will make a correction for only the first lines:</p> <pre><code>- (NSBitmapImageRep *)bitmapImageRepresentation { NSArray *ret =[self representations]; for( NSImageRep *rep in [self representations] ) if( [rep isKindOfClass:[NSBitmapImageRep class]] ) return rep; return nil; } </code></pre> <p>This will extract the first <code>NSBitmapImageRep</code> if it is member in the representations or will return nil, if there is no <code>NSBitmapImageRep</code>. I'll give you another solution which will always work whatever <code>NSImageReps</code> are in the representations: <code>NSBitmapImageRep</code>, <code>NSPDFImageRep</code> or <code>NSCGImageSnapshotRep</code> or ...</p> <pre><code>- (NSBitmapImageRep *)bitmapImageRepresentation { CGImageRef CGImage = [self CGImageForProposedRect:nil context:nil hints:nil]; return [[[NSBitmapImageRep alloc] initWithCGImage:CGImage] autorelease]; } </code></pre> <p>Or to avoid subclassing of NSImage you may write:</p> <pre><code>NSImage *img = [[[NSImage alloc] initWithContentsOfFile:filename] autorelease]; CGImageRef CGImage = [img CGImageForProposedRect:nil context:nil hints:nil]; NSBitmapImageRep *rep = [[[NSBitmapImageRep alloc] initWithCGImage:CGImage] autorelease]; </code></pre> <p>This will only return a single <code>NSBitmapImageRep</code> which maybe not good enough if the image contains more than one representation (e.g. a lot of <code>NSBitmapImageRep</code>s from TIFF files). But adding some code is straightforward.</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload