为什么这段代码将 artistImage 设置为宽度为 0 高度为 0 的图像?
NSURL *artistImageURL = [NSURL URLWithString:@"http://userserve-ak.last.fm/serve/252/8581581.jpg"];
NSImage *artistImage = [[NSImage alloc] initWithContentsOfURL:artistImageURL];
最佳答案
正如 Ken 所写,这张图片中的 DPI 乱七八糟。如果您想强制 NSImage 设置真实图像大小(忽略 DPI),请使用 http://borkware.com/quickies/one?topic=NSImage 中描述的方法:
NSBitmapImageRep *rep = [[image representations] objectAtIndex: 0];
NSSize size = NSMakeSize([rep pixelsWide], [rep pixelsHigh]);
[image setSize: size];
关于objective-c - NSImage 行为怪异,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/2190027/