Note that there are some explanatory texts on larger screens.

plurals
  1. POTrying to turn [NSImage imageNamed:NSImageNameUser] into NSData
    primarykey
    data
    text
    <p>If I create an <code>NSImage</code> via something like:</p> <pre><code>NSImage *icon = [NSImage imageNamed:NSImageNameUser]; </code></pre> <p>it only has one representation, a <code>NSCoreUIImageRep</code> which seems to be a private class.</p> <p>I'd like to archive this image as an <code>NSData</code> but if I ask for the <code>TIFFRepresentation</code> I get a small icon when the real <code>NSImage</code> I originally created seemed to be vector and would scale up to fill my image views nicely.</p> <p>I was kinda hoping images made this way would have a <code>NSPDFImageRep</code> I could use.</p> <p>Any ideas how can I get an <code>NSData</code> (pref the vector version or at worse a large scale bitmap version) of this <code>NSImage</code>?</p> <p><strong>UPDATE</strong></p> <p>Spoke with some people <a href="https://twitter.com/gte/status/121641784005754880" rel="noreferrer">on Twitter</a> and they suggested that the real source of these images are multi resolution icns files (probably not vector at all). I couldn't find the location of these on disk but interesting to hear none-the-less.</p> <p>Additionally they suggested I create the system NSImage and manually render it into a high res NSImage of my own. I'm doing this now and it's working for my needs. My code:</p> <pre><code>+ (NSImage *)pt_businessDefaultIcon { // Draws NSImageNameUser into a rendered bitmap. // We do this because trying to create an NSData from // [NSImage imageNamed:NSImageNameUser] directly results in a 32x32 image. NSImage *icon = [NSImage imageNamed:NSImageNameUser]; NSImage *renderedIcon = [[NSImage alloc] initWithSize:CGSizeMake(PTAdditionsBusinessDefaultIconSize, PTAdditionsBusinessDefaultIconSize)]; [renderedIcon lockFocus]; NSRect inRect = NSMakeRect(0, 0, PTAdditionsBusinessDefaultIconSize, PTAdditionsBusinessDefaultIconSize); NSRect fromRect = NSMakeRect(0, 0, icon.size.width, icon.size.width);; [icon drawInRect:inRect fromRect:fromRect operation:NSCompositeCopy fraction:1.0]; [renderedIcon unlockFocus]; return renderedIcon; } </code></pre> <p>(Tried to post this as my answer but I don't have enough reputation?)</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

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