Skip to content
Chris Petersen edited this page Oct 16, 2014 · 3 revisions

png->u8vector returns a loaded PNG file as an u8vector. The optional arguments can be used to load the image into a matrix of desired size, e.g. powers of 2 for textures.

Parameter Description
fname PNG file to obtain information from
w0 Optional: Width of matrix in u8vector
h0 Optional: Height of matrix in u8vector

Example

Example 1: Modify the panda-icon.png from uSquish to remove all RED color.

> (define fname (string-append (system-directory) (system-pathseparator) "panda-icon.png"))
> (define img (png->u8vector fname))
> (let loop ((i 0))
    (if (fx= i (u8vector-length img))   
      #t
      (begin
        (u8vector-set! img i 0)
        (loop (fx+ i (png-stride fname))) 
      )
    )
  )
#t
> (u8vector->png img "panda-changed.png" (png-width fname) (png-height fname))
#t
Clone this wiki locally