wxWidgets 3.1.3 图标在 mac 下加载 - ICNS 文件不可读?

wxWidgets 3.1.3 icon loading under mac - ICNS files unreadable?

本文关键字:文件 ICNS 加载 图标 mac wxWidgets      更新时间:2023-10-16

现在似乎不可能在mac下加载.icns文件。过去可以使用wxIcon和wxIconLocation,例如。

wxMimeTypesManager manager;
wxFileType *type = manager.GetFileTypeFromExtension("zip");
wxIconLocation location;
if(type->GetIcon(&location))
{
// location m_filename is something like "/System/Library/CoreServices/Applications/Archive Utility.app/Contents/Resources/bah-zip.icns"
wxIcon icon;
// This will FAIL now as there is no handler for wxBITMAP_TYPE_ICON...
icon.LoadFile(location.GetFileName(), wxBITMAP_TYPE_ICON, 32, 32);
}

wxMimeTypesManager::GetFileTypeFromExtension 返回一个 wxFileType。 然后,您可以使用 wxFileType::GetIcon 返回 wxIconLocation。

wxIconLocation::GetFileName(( 返回 OSX 下的.icns文件。如果您将wxBITMAP_TYPE_ICON传递给wxIcon::LoadFile,则这曾经可以在wxWidgets 2.9.1下作为wxIcon加载,因为这会强制wxIcon::LoadIconFromFile (src/osx/carbon/icon.cpp(使用ReadIconFromFSRef从icns加载。

但是由于所有的碳代码都消失了,现在我无法从.icns文件中加载任何内容。

我现在该怎么做?

编辑:我使用了以下配置:configure --disable-shared --enable-unicode --prefix="$(pwd)" --enable-stc --enable-ipc --enable-base64 --enable-exceptions --enable-fontenum --enable-fs_archive --enable-stdpaths --enable-sysoptions --enable-threads --enable-url --enable-aui --enable-graphics_ctx --enable-printarch --enable-timer --enable-ribbon --enable-webview --enable-display --enable-splash --enable-snglinst --enable-printfposparam --with-opengl --with-osx_cocoa --with-expat=builtin --with-cxx=11 --enable-cxx11 --enable-stl --enable-std_iostreams --enable-std_string --enable-ftp --enable-http --enable-fileproto --enable-sockets --enable-ipv6 --enable-dataobj --enable-ipc --enable-any --enable-arcstream --enable-backtrace --enable-cmdline --enable-datetime --enable-debugreport --enable-dynamicloader --enable-exceptions --enable-ffile --enable-file --enable-filehistory --enable-filesystem --enable-fontmap --enable-fs_inet --enable-fs_zip --enable-fsvolume --enable-fswatcher --enable-geometry --enable-sound --enable-stopwatch --enable-streams --enable-tarstream --enable-textbuf --enable-textfile --enable-variant --enable-zipstream --enable-protocol --enable-protocol-http --enable-protocol-ftp --enable-protocol-file --enable-html --enable-htmlhelp --enable-propgrid --enable-svg --enable-clipboard --enable-dnd --enable-accel --with-osx_cocoa --enable-debug --with-libpng=builtin --with-libjpeg=builtin --with-zlib=builtin --with-libtiff=builtin

不幸的是,这对我来说是一个错误。目前wxIcon::LoadIconFromFile()只是在wxOSX_ICON_USE_NSIMAGE==1时总是返回 false,这是默认值。您可以尝试在setup.h中将wxOSX_BITMAP_NATIVE_ACCESS设置为 0 并重建作为非常短期的修复,但真正需要做的是使用 NSImage 实现此功能,可能使用[NSImage initWithContentsOfFile:]