#!ruby -Ks # -*- mode: ruby; encoding: sjis -*- # Last updated: <2014/01/03 16:22:58 +0900> # # 画像をネットから読み込むテストその2 # 以下の記事を参考に処理 # # ネット上の画像をRubyでダウンロードする方法 - ダークな糸 # http://dark7110.blog.fc2.com/blog-entry-3.html require 'net/http' require 'uri' require 'dxruby' uri = URI("http://www.geocities.jp/mieki256jp/resource/_dxruby_image_sprite1.png") fn = File.basename(uri.path) unless File.exist?(fn) # カレントフォルダ内に画像が無ければダウンロード puts "not found #{fn}" puts "download #{uri.host} #{uri.path}" http = Net::HTTP.new(uri.host) response = http.get(uri.path) image = response.body file = open(fn, "wb") file.write(image) file.close() else puts "found #{fn}" end img = Image.load(fn) Window.loop do break if Input.keyPush?(K_ESCAPE) Window.draw(0, 0, img) end