How do I set the image resolution?

I am using Seesaw to interact with Swing.

I have some icons defined this way:

(def label :icon 
           (clojure.java.io/resource "some_image.png"))

      

I want to render "some_image.png" in a different resolution. If I just set the borders, I only get part of the image.

How can I achieve this?

+3


source to share


1 answer


you can do this by going downstairs in Swing. basically, manipulate the file like a Swing Image. if you have the size you want, Seesaw's capabilities icon

are flexible in terms of what can be passed (see https://daveray.github.io/seesaw/seesaw.icon-api.html ); you can pass Swing Image to a function label

.

(defn imagetest []
  (let [w (frame :title "Image Test" :width 400 :height 400)
        img (.getScaledInstance 
              (javax.imageio.ImageIO/read 
                (io/resource "racecar.gif")) 400 400 1)
        lbl (label :icon img)
        pnl (horizontal-panel :items [lbl])]
    (config! w :content pnl)
    (show! w)))

      



Note: 1

which I pass as the final arg for .getScaledInstance

for the flag SCALE_DEFAULT

; more details here: https://docs.oracle.com/javase/7/docs/api/constant-values.html#java.awt.Image.SCALE_DEFAULT

+1


source







All Articles