From: Kamaljeet Saini Date: 2009-01-29T01:28:07+09:00 Subject: Re: Converting binary image file to bmp file using RMagick2.0 Hi, I was able to get 1 binary files from dev. and tried the following code but .bmp goes bad still. Possible please to look into and advice. Binary files attached as zip file. require 'rmagick' file_name = "C:/1.txt" # the binary file image_file_name = "C:/1.bmp" # the expected file to be generated image = Magick::Image.new(800, 480) file = File.open(file_name,"rb").read one = [] two = [] three = [] file.unpack('S*').each { |x| three << (x & 0x1F) * 8 #puts "Three : #{three}" two << ((x >> 5) & 0x1F) * 8 #puts "Two : #{two}" one << ((x >> 10) & 0x1F) * 8 #puts "One : #{one}" } bufferscreen_height=480 bufferscreen_width=800 k=0 for i in 0...bufferscreen_height for j in 0...bufferscreen_width q=Magick::Pixel.new(one[k],two[k],three[k],0) #puts "i is : #{i} and j is : #{j} R:#{one[k]} G:#{two[k]} B:#{three[k]}" image.pixel_color(j,i,q) k += 1 end end image.write(image_file_name) thanks Attachments: http://www.ruby-forum.com/attachment/3217/1.zip -- Posted via http://www.ruby-forum.com/.