Imageクラスの拡大縮小機能
要望があったのでとりあえずRubyで実装。
バグあるかもしれんけど、なんとなく動いてるので。
こんな感じで作れば遅いけど、リアルタイム処理をするのではなくデータ作成用としてなら使える。
補間も高速化もなにもしていないので品質はお察し。
require 'dxruby' class Image def strechRect(x1, y1, w1, h1, image, x2, y2, w2, h2) if image.width < x2 + w2 or image.height < y2 + h2 or self.width < x1 + w1 or self.height < x1 + h1 or x1 < 0 or y1 < 0 or w1 < 0 or h1 < 0 or x2 < 0 or y2 < 0 or w2 < 0 or h2 < 0 raise "座標がはみ出してるようです" end dx = w2.quo(w1) dy = h2.quo(h1) x = x2 y = y2 for i in y1...(y1 + h1) for j in x1...(x1 + w1) self[j, i] = image[x, y] x = x + dx end x = x2 y = y + dy end return self end end image0 = Image.new(100,100).circleFill(49,49,49, [255,0,255,0]). # もとねた circleFill(49,49,30, [255,128,128,0]) image1 = Image.new(50,50) # 縮小先 image2 = Image.new(200,200) # 拡大先 image1.strechRect(0, 0, 50, 50, image0, 0, 0, 100, 100) # 縮小 image2.strechRect(0, 0, 200, 200, image0, 0, 0, 100, 100) # 拡大 Window.loop do break if Input.keyPush?(K_ESCAPE) Window.draw(0,0,image0) Window.draw(0,100,image1) Window.draw(0,150,image2) end