require 'zxing' # You can decode a URL... ZXing.decode 'http://2d-code.co.uk/images/bbc-logo-in-qr-code.gif' # ... or a file path... ZXing.decode '/Users/ecin/qrcode.png' # ... or a File object... ZXing.decode File.open('qrcode.png') # ... or anything that returns a URL or file path when #path or #to_s # is called on it. class Image attr_reader :path def initialize(path); @path = path end end image = Image.new('qrcode.png') ZXing.decode image # #decode returns nil if it can't decode the image. ZXing.decode 'image_without_a_code.png' # => nil # #decode! will raise an error if it can't decode the image. ZXing.decode! 'image_without_a_code.png' # => NativeException # Feel free to include ZXing to shorten the call. include ZXing decode 'qrcode.png'
A Decodable module is included (pun intended) to ease using the library with objects that return the URL or file path to decode when #path or #to_s is called.
require 'zxing/decodable' class File include Decodable end file = File.open('qrcode.png') file.decode
此处可能存在不合适展示的内容,页面不予展示。您可通过相关编辑功能自查并修改。
如您确认内容无涉及 不当用语 / 纯广告导流 / 暴力 / 低俗色情 / 侵权 / 盗版 / 虚假 / 无价值内容或违法国家有关法律法规的内容,可点击提交进行申诉,我们将尽快为您处理。