Reputation: 13
I have message from server in following format
result = "123,-23,12,...,54,-53"
That message represents array byte of image. How can I convert this to actual image?
I converted this result to array of ints and tried with:
File.open( 'imageX.png', 'wb' ) do |output|
splited.each do | byte |
output.print byte
end
end
But image is not recognizable. What am I missing?
Upvotes: 1
Views: 883
Reputation: 2052
I suspect you'll want to try something like:
File.write("imageX.png", result.split(',').map(&:to_i).pack('C*'))
This converts it to bytes then "packs" each one as a character (one byte).
I hope that helps.
Cheers!
Upvotes: 4