获取垃圾桶的全尺寸图标

发布于 2024-11-13 05:52:46 字数 81 浏览 1 评论 0原文

我正在尝试在我的应用程序中显示垃圾箱的图标,包括空的和满的。我尝试了多种方法来获取图标,但每次的大小都是 32x32。您知道获得全尺寸图像的方法吗?

I am trying to display the icons of the Trash can in my app, both empty and full. I've tried several methods to get the icons, but each time the size is 32x32. Do you know a way to get a full size image?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(4

硪扪都還晓 2024-11-20 05:52:46

我假设您通过 NSWorkspace 获取垃圾桶图标,使用 IconsCore.h 中的 kTrashIcon 常量(如果不是,则为:

NSImage* image = [[NSWorkspace sharedWorkspace] iconForFileType:NSFileTypeForHFSTypeCode(kTrashIcon)];

…这个 NSImage 包含多种不同尺寸的表示形式。如果您想要最大的,只需迭代可用的表示即可找到它:

NSEnumerator* representationEnumerator = [[image representations] objectEnumerator];
NSSize biggestSize = NSMakeSize(0, 0);
NSSize size;
while ((size = [(NSImageRep*)[representationEnumerator nextObject] size]).width) {
    if (size.width > biggestSize.width) {
        biggestSize = size;
    }
}
[image setSize:biggestSize];

…在我的计算机上,这会导致 NSImage 设置为 512x512。

I assume that you’re getting the trash icon through NSWorkspace, using the kTrashIcon constant from IconsCore.h (if you’re not, this is :

NSImage* image = [[NSWorkspace sharedWorkspace] iconForFileType:NSFileTypeForHFSTypeCode(kTrashIcon)];

…this NSImage contains representations in a number of different sizes. If you want the biggest one, just iterate through the available representations to find it:

NSEnumerator* representationEnumerator = [[image representations] objectEnumerator];
NSSize biggestSize = NSMakeSize(0, 0);
NSSize size;
while ((size = [(NSImageRep*)[representationEnumerator nextObject] size]).width) {
    if (size.width > biggestSize.width) {
        biggestSize = size;
    }
}
[image setSize:biggestSize];

…On my computer, this results in an NSImage set to 512x512.

很糊涂小朋友 2024-11-20 05:52:46

如果您要从以下文件创建图像,请注意 32px x 32px 只是默认尺寸

/System/Library/CoreServices/CoreTypes.bundle/Contents/Resources/TrashIcon.icns

: 将其调整为您想要的大小:

NSString *path = @"/System/Library/CoreServices/CoreTypes.bundle/Contents/Resources/TrashIcon.icns";
NSImage *image = [[[NSImage alloc] initWithContentsOfFile:path] autorelease];
[image setSize:NSMakeSize(512.0, 512.0)];

当您这样做时,NSImage 将自动从可用的图像代表中选择适当的图像代表。例如,记录图像会显示以下描述:

image == NSImage 0x102e16bc0 Size={512, 512} Reps=(

    "NSBitmapImageRep 0x102e1f650 Size={512, 512} ColorSpace=(not yet loaded)
      BPS=8 BPP=(not yet loaded) Pixels=512x512 Alpha=YES Planar=NO
  Format=(not yet loaded) CurrentBacking=nil (faulting) CGImageSource=0x102e187d0",

    "NSBitmapImageRep 0x102e24c80 Size={256, 256} ColorSpace=(not yet loaded)
     BPS=8 BPP=(not yet loaded) Pixels=256x256 Alpha=YES Planar=NO
  Format=(not yet loaded) CurrentBacking=nil (faulting) CGImageSource=0x102e187d0",

    "NSBitmapImageRep 0x102e25540 Size={128, 128} ColorSpace=(not yet loaded)
    BPS=8 BPP=(not yet loaded) Pixels=128x128 Alpha=YES Planar=NO
  Format=(not yet loaded) CurrentBacking=nil (faulting) CGImageSource=0x102e187d0",

    "NSBitmapImageRep 0x102e25e30 Size={32, 32} ColorSpace=(not yet loaded)
    BPS=8 BPP=(not yet loaded) Pixels=32x32 Alpha=YES Planar=NO 
  Format=(not yet loaded) CurrentBacking=nil (faulting) CGImageSource=0x102e187d0",

    "NSBitmapImageRep 0x102e26720 Size={16, 16} ColorSpace=(not yet loaded)
    BPS=8 BPP=(not yet loaded) Pixels=16x16 Alpha=YES Planar=NO
  Format=(not yet loaded) CurrentBacking=nil (faulting) CGImageSource=0x102e187d0"
)

大多数代表文件图标的图像(例如 NSWorkspace 返回的图像)将有多种可用尺寸,但默认尺寸为 32 x 32。

If you're creating an image from the following file, then realize that 32px x 32px is simply the default size:

/System/Library/CoreServices/CoreTypes.bundle/Contents/Resources/TrashIcon.icns

Just resize it to the size you'd like:

NSString *path = @"/System/Library/CoreServices/CoreTypes.bundle/Contents/Resources/TrashIcon.icns";
NSImage *image = [[[NSImage alloc] initWithContentsOfFile:path] autorelease];
[image setSize:NSMakeSize(512.0, 512.0)];

When you do so, the NSImage will automatically choose the appropriate image rep from those that are available. For example, logging the image shows the following description:

image == NSImage 0x102e16bc0 Size={512, 512} Reps=(

    "NSBitmapImageRep 0x102e1f650 Size={512, 512} ColorSpace=(not yet loaded)
      BPS=8 BPP=(not yet loaded) Pixels=512x512 Alpha=YES Planar=NO
  Format=(not yet loaded) CurrentBacking=nil (faulting) CGImageSource=0x102e187d0",

    "NSBitmapImageRep 0x102e24c80 Size={256, 256} ColorSpace=(not yet loaded)
     BPS=8 BPP=(not yet loaded) Pixels=256x256 Alpha=YES Planar=NO
  Format=(not yet loaded) CurrentBacking=nil (faulting) CGImageSource=0x102e187d0",

    "NSBitmapImageRep 0x102e25540 Size={128, 128} ColorSpace=(not yet loaded)
    BPS=8 BPP=(not yet loaded) Pixels=128x128 Alpha=YES Planar=NO
  Format=(not yet loaded) CurrentBacking=nil (faulting) CGImageSource=0x102e187d0",

    "NSBitmapImageRep 0x102e25e30 Size={32, 32} ColorSpace=(not yet loaded)
    BPS=8 BPP=(not yet loaded) Pixels=32x32 Alpha=YES Planar=NO 
  Format=(not yet loaded) CurrentBacking=nil (faulting) CGImageSource=0x102e187d0",

    "NSBitmapImageRep 0x102e26720 Size={16, 16} ColorSpace=(not yet loaded)
    BPS=8 BPP=(not yet loaded) Pixels=16x16 Alpha=YES Planar=NO
  Format=(not yet loaded) CurrentBacking=nil (faulting) CGImageSource=0x102e187d0"
)

Most images that represent file icons such as those returned by NSWorkspace will have many sizes available, though 32 x 32 is the default size.

梦与时光遇 2024-11-20 05:52:46

/System/Library/CoreServices/Dock.app/Contents/Resources/trashfull.png
/System/Library/CoreServices/Dock.app/Contents/Resources/trashempty.png

这是 128x128 的图标

/System/Library/CoreServices/Dock.app/Contents/Resources/trashfull.png
/System/Library/CoreServices/Dock.app/Contents/Resources/trashempty.png

It's 128x128 icon

眼眸里的那抹悲凉 2024-11-20 05:52:46

在 Google 图片上搜索“Mac OS 垃圾”

Search "Mac OS Trash" on Google Images

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文