[racket] Using *.ico files

From: Kieron Hardy (kieron.hardy at gmail.com)
Date: Mon Sep 10 16:41:35 EDT 2012

Thanks Danny, that does the trick nicely.

Cheers,

Kieron.

On Mon, Sep 10, 2012 at 2:00 PM, Danny Yoo <dyoo at hashcollision.org> wrote:

> > I see the function read-icos in file/ico, and also the function ico->argb
> > which gives a bytes? that represents an argb image, but I can't figure
> out
> > how to get from a bytes? to an actual argb?.
>
> Hi Kieron,
>
> An argb has a vector that we can probably mutate.  It also holds width
> and height, so we need to preserve those too...
>
> Hmm.  Something VERY strange is happening with the alphas being
> produced by ico->argb vs the alphas expected by the bitmap functions.
> They seem... flipped!
>
> Here's source that should do the trick for you, but I'm confused about
> what's going on with the alpha transparency stuff:
>
> ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
> #lang racket/base
>
> (require file/ico)
> (require mrlib/cache-image-snip)
>
> (define (ico->bitmap x)
>   (define argb-bytes (ico->argb x))
>   (argb->bitmap
>    (make-argb (for/vector ([b argb-bytes]
>                            [i (in-naturals)])
>                 (if (= (remainder i 4) 0)
>                     (- 255 b)
>                     b))
>               (ico-width x)
>               (ico-height x))))
>
>
>
> ;; For example
> ;;(map (lambda (x) (ico->bitmap x))
> ;;     (read-icos "001_01.ico"))
>
> ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
>
>
>
> Good luck!
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.racket-lang.org/users/archive/attachments/20120910/ef8caba5/attachment-0001.html>

Posted on the users mailing list.