1. --!movie
  2.  
  3. global $
  4.  
  5. ----------------------------------------
  6. -- This demo converts a filmstrip image with alpha channel to an APNG file with alpha channel.
  7. ----------------------------------------
  8. on startMovie
  9.  
  10.     -- CONFIG
  11.     DUR = 50 -- 50 ms = 20 fps
  12.  
  13.     -- libs
  14.     $.import("console").show()
  15.  
  16.     -- load strip BMP (with alpha channel and 29 frames of 100x100px) into image
  17.     m = new(#bitmap)
  18.     m.importFileInto($.PATH&"input\web_heart_strip_32bit_alpha.bmp", [#trimWhiteSpace: FALSE])
  19.     webHeart = m.image
  20.     webHeartMask = webHeart.extractAlpha().createMask()
  21.  
  22.     -- create an instance of the APNG lib
  23.     apng = $.include($.PATH&"apng.ls").new()
  24.  
  25.     ms = the milliseconds
  26.  
  27.     -- initialize APNG (i.e. start creation of new APNG file)
  28.     apng.init(0) -- 0 = loop forever
  29.  
  30.     -- add frames in a loop
  31.     w = 100
  32.     h = 100
  33.     r = rect(0, 0, w, h)
  34.  
  35.     frameImg = image(w, h, 32)
  36.     frameImg.setAlpha(0)
  37.     frameImg.useAlpha = 1
  38.  
  39.     cnt = webHeart.width / w
  40.     repeat with i = 1 to cnt
  41.  
  42.         -- extract next frame from strip
  43.         frameImg.fill(frameImg.rect, rgb(0,0,0))
  44.         frameImg.setAlpha(0)
  45.         frameImg.copyPixels(webHeart, r, r.offset((i-1)*w, 0), [#maskImage:webHeartMask])
  46.  
  47.         -- add frame to APNG
  48.         apng.addFrame(frameImg, DUR)
  49.     end repeat
  50.  
  51.     ms = the milliseconds-ms
  52.  
  53.     -- save the APNG as file
  54.     apng.writeFile($.PATH&"animation_web_heart.png")
  55.  
  56.     out("Done. APNG was generated in "&ms&" milliseconds.")
  57. end
  58.  
[raw code]