ImagePut icon indicating copy to clipboard operation
ImagePut copied to clipboard

can gdip save as ".ico"?

Open hyaray opened this issue 2 years ago • 4 comments

GdipSaveImageToFile seems not support the filetype... is there any other method to do this? thanks very much!!!

hyaray avatar Nov 05 '22 15:11 hyaray

Can you provide some working GDI+ code? I will investigate.

On Sat, Nov 5, 2022 at 11:30 hyaray @.***> wrote:

GdipSaveImageToFile seems to support the filetype... is there any other method to do this? thanks very much!!!

— Reply to this email directly, view it on GitHub https://github.com/iseahound/ImagePut/issues/21, or unsubscribe https://github.com/notifications/unsubscribe-auth/ACKTTVBSRQ3OEM4RLHGZZBLWGZ4SNANCNFSM6AAAAAARX7FGAA . You are receiving this because you are subscribed to this thread.Message ID: @.***>

iseahound avatar Nov 05 '22 15:11 iseahound

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)

hyaray avatar Nov 05 '22 15:11 hyaray

Depending on your use case, you can actually change the *.png extension to *.ico, and it should work.

iseahound avatar Nov 05 '22 19:11 iseahound

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.

iseahound avatar Nov 08 '22 14:11 iseahound