我可以访问文件的二进制数据,并将其存储在变量中,像这样:
s = File.binread("sample_22122015_03.jpg")
bits = s.unpack("B*")[0]
其中bits的数据是像这样的“101001001010100100.......”
然而,我想做一些更改并将二进制数据再次写回到新图像中,但我无法做到。
我正在使用
File.open('shipping_label_new.jpg', 'wb') do|f|
f.write(Base64.decode64(bits))
end
但是它无法正常运行,我发现图像已损坏。