带有 PNG 数据的 ICO 文件

问题描述 投票:0回答:2

查看一些包含 PNG 数据而不是 ICO 的 ICO 文件,我正在尝试创建相同的文件。示例:

$ identify sample.ico 

sample.ico[0] PNG 32x32 32x32+0+0 8-bit sRGB 884B 0.000u 0:00.000
sample.ico[1] PNG 16x16 16x16+0+0 8-bit sRGB 884B 0.000u 0:00.000

$ file sample.ico
sample.ico: MS Windows icon resource - 2 icons, 
32x32, 16 colors withPNG image data, 32 x 32, 8-bit/color RGBA, non-interlaced, 4 bits/pixel, 
16x16, 16 colors withPNG image data, 16 x 16, 8-bit/color RGBA, non-interlaced, 4 bits/pixel

我发现我可以做这样的事情来获得PNG ICO:

$ convert icon-32x32.png png8:test1.ico
$ identify test1.ico

test1.ico PNG 32x32 32x32+0+0 8-bit sRGB 934B 0.000u 0:00.000

但是如果我使用多个输入文件,我会得到多个输出文件:

$ convert icon-16x16.png icon-32x32.png png8:test2.ico
$ ls -1 test2*

test2-0.ico
test2-1.ico

不添加前缀

png8:
会将数据转换为 ICO。

$ convert icon-16x16.png icon-32x32.png test3.ico
$ identify test3.ico 

test3.ico[0] ICO 16x16 16x16+0+0 32-bit sRGB 5.43KB 0.000u 0:00.000
test3.ico[1] ICO 32x32 32x32+0+0 32-bit sRGB 5.43KB 0.000u 0:00.000

如果文件对于 ICO 格式来说太大,则“保留”PNG:

$ convert ../icon-32x32.png ../icon-512x512.png test4.ico
$ identify test4.ico

test3.ico[0] ICO 32x32 32x32+0+0 32-bit sRGB 53.4KB 0.000u 0:00.000
test3.ico[1] PNG 512x512 512x512+0+0 8-bit sRGB 53.4KB 0.000u 0:00.000

如何在 ImageMagick 中创建包含所有尺寸的 PNG 数据的 ICO 文件?

imagemagick png imagemagick-convert ico
2个回答
1
投票

尚未找到任何使用 imagemagick 的解决方案,但可以使用 GIMP。

只需为每个尺寸创建一个图层并导出为

file.ico

在出现的选项对话框中勾选

Compress (PNG)

还可以设置

bpp
等。对于较低的分辨率,可以使用例如:

  • 16x16
    4bpp, 1-bit alpha, 16-slots palette
  • 24x24
    4bpp, 1-bit alpha, 16-slots palette
  • 32x32
    8bpp, 1-bit alpha, 256-slots palette
  • 48x48
    ...

0
投票

您实际上可以仅使用 Windows Direct2D API 完成从 SVG 到 ICO 或 SVG 到 PNG 或 PNG 到 ICO 的整个转换,而无需任何第三方工具。

我今天构建了该工具。 ICO 格式有一些奇怪的问题,因为它实际上可以直接支持旋转和 PNG,但许多工具不能正确理解它。所以最好直接从 SVG 或 PNG 转换为更严格的 GUID_WICPixelFormat32bppPBGRA 格式并使用

D2D1_MATRIX_3X2_F transformMatrix = D2D1::Matrix3x2F::Scale(1.0f, -1.0f); // Flip y-axis
transformMatrix._32 = static_cast<float>(renderHeight); // Reposition y-axis origin

要查看基础知识,请查找

DrawSvgDocument
ComPtr<ID2D1DeviceContext5> dc;

    // Create PNG encoder
    ComPtr<IWICBitmapEncoder> encoder;
    hr = wicFactory->CreateEncoder(GUID_ContainerFormatPng, nullptr, &encoder);
© www.soinside.com 2019 - 2024. All rights reserved.