From: Kamaljeet Saini Date: 2009-01-20T03:05:05+09:00 Subject: Converting binary image file to bmp file using RMagick2.0 We are trying to convert "image1.txt" file which is a binary file to "image1.bmp" file usng Ruby + RMagick2.0 but not able to get the required output that is "Menu.bmp". Following the attached code that we have reached so far. Look forward to get some help as how to get an output like "Menu.bmp" from the file called "image1.txt" I was not able to attached all the three files ( image1.txt, image1.bmp and Menu.bmp) So just attached the source file "image1.txt" and if you run the following case, it wll generate "image1.bmp" require 'rmagick' file_name = "C:/image1.text" # the binary file image_file_name = "C:/image1.bmp" # the expected file to be generated image = Magick::Image.new(704, 480) file = File.read(file_name) #=begin one = [] two = [] three = [] p = 0 l = 1 file.each_byte { |x| case l when 1 one << x #getOne=((moveOne << 1 + 16) >> 11 + 16) #one << getOne l += 1 when 2 two << x #getTwo=((moveTwo << 6 + 16) >> 11 + 16) #two << getTwo l += 1 when 3 three << x #getThree=((moveThree << 11 + 16) >> 11 + 16) #three << getThree p += 1 #puts "#{one} #{two} #{three}" l = 1 end } bufferscreen_height=480 bufferscreen_width=704 k=0 for i in 0..bufferscreen_height #puts "Height: #{i} \n\n" for j in 0..bufferscreen_width #puts "Width: #{j} \n\n" #q=Magick::Pixel.new(25,75,34, 0) q=Magick::Pixel.new(one[k],two[k],three[k],0) #q=Magick::Pixel.new(((one[k] << 17) >> 27), ((two[k] << 22) >> 27), ((three[k] << 27) >> 27), 0) #puts "R:#{one[k]} G:#{two[k]} B:#{three[k]}" #puts "\n\n" #y, z = p.divmod(704) image.pixel_color(j,i,q) k += 1 end end image.write(image_file_name) #=end Attachments: http://www.ruby-forum.com/attachment/3176/image1.zip -- Posted via http://www.ruby-forum.com/.