2009/1/23 Kamaljeet Saini <kamaljeet_singh_saini / hotmail.com>
>
> The above posting code worked fine for 704/480 binary to image file but
> for the attached file the same code is not working. Its 800/480 binary
> file. Possible to advice please. Im try to use the following code.
>
> require 'rmagick'
> file_name = "C:/image2.text" # the binary file
> image_file_name = "C:/image2.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)
>    image.pixel_color(j,i,q)
>    k += 1
>  end
> end
> image.write(image_file_name)
>
> Attachments:
> http://www.ruby-forum.com/attachment/3194/image2.text

 I guess your input binary file is corrupted. It's size must be
768000(800x480x2) bytes but it is only  76801 bytes.

Regards,

Park Heesob