tips_img_030 - spoolkitamura/nyle-doc-jp GitHub Wiki

画像を拡大/縮小するには?

画像を読み込む際の load_imageメソッドのオプション sxおよび sy
画像の縦横それぞれの拡大率を指定することができます。

[関連情報]
load_image

 

  • 画像を表示する(原寸)
require 'nyle'

class Screen < Nyle::Screen
  def initialize
    super(200, 300, {bgcolor: :IVORY})
    @image = Nyle.load_image("./j1.png", {color_key: :WHITE})
  end
  def draw
    Nyle.draw_image(90, 210, @image, {pos: :CENTER})
  end
end

Screen.new.show_all
Nyle.main

[実行結果]


  • 画像を表示する(横1.3倍、縦0.7倍)
require 'nyle'

class Screen < Nyle::Screen
  def initialize
    super(200, 300, {bgcolor: :IVORY})
    @image = Nyle.load_image("./j1.png", {color_key: :WHITE, sx: 1.3, sy: 0.7})   # 拡大率/縮小率を指定
  end
  def draw
    Nyle.draw_image(90, 210, @image, {pos: :CENTER})
  end
end

Screen.new.show_all
Nyle.main

[実行結果]