[racket] Using *.ico files

From: Danny Yoo (dyoo at hashcollision.org)
Date: Mon Sep 10 16:00:55 EDT 2012

> 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!

Posted on the users mailing list.