can gdip save as ".ico"?
Opened this issue · 4 comments
GdipSaveImageToFile seems not support the filetype...
is there any other method to do this?
thanks very much!!!
sorry, I think GdipSaveImageToFile
may not able to do this.
I'm tring python instead.
import os,sys
from PIL import Image
fp0 = r"c:\1.png"
fp1 = os.path.splitext(fp0)[0] + ".ico"
size = (16,16)
im = Image.open(fp0).resize(size)
im.save(fp1)
Depending on your use case, you can actually change the *.png extension to *.ico, and it should work.
Just a little update: This needs some more investigation. In general, an *.ico file contains about 9 resolutions. These are mostly encoded as a bitmap and stored sequentially.
So something like generating:
- 16 x 16
- 64 * 64
- 256 x 256
could be done automatically. I should also allow passing an array of sizes as well.
Here's the interesting part: An ICO file can host embedded PNGs. Since the IconDirEntry header uses a UCHAR
for storage of width and height, the maximum width and height is 256 x 256
which is the maximum value for an unsigned char (one byte). But it will recognize one special PNG with an icon size of 256 x 256 and will use the width and height embedded inside the PNG instead. So theoretically, the size limit inside an ICO can be bigger than 256 x 256.