save screenshots.

This commit is contained in:
Bryce Covert
2015-11-21 17:59:07 -08:00
parent 5da5995894
commit 04a03f281b
2 changed files with 23 additions and 8 deletions

View File

@@ -1,7 +1,10 @@
(ns advent.steam
(:require [play-clj.core :refer :all]
[clojure.edn :as edn])
(:import [java.nio ByteBuffer CharBuffer]))
(:import [java.nio ByteBuffer CharBuffer]
[java.io ByteArrayOutputStream]
[com.badlogic.gdx.graphics PixmapIO$PNG]
))
(def has-steam?
(try
@@ -90,5 +93,21 @@
bytes# (make-array Byte/TYPE len#)]
(do (.fileRead rs# ~filename bb# len#)
(.get bb# bytes#)
(println (count bytes#))
bytes#)))
(.readBytes (files! :local filename))))
(defn save-screenshot [pm filename]
(if has-steam?
(let [rs (SteamRemoteStorage. nil)
png (PixmapIO$PNG. (* (.getWidth pm) (.getHeight pm) 1.5))
baos (ByteArrayOutputStream. (* (.getWidth pm) (.getHeight pm) 1.5))
_ (.write png baos pm)
bytes (.toByteArray baos)
bb (ByteBuffer/allocateDirect (count bytes))]
(.put bb bytes)
(.fileWrite rs filename bb (count bytes)))
(let [f (files! :local filename)
png (PixmapIO$PNG. (* (.getWidth pm) (.getHeight pm) 1.5))]
(.write png f pm)
(.dispose png))))