Version française
Home     About     Download     Resources     Contact us    

This site is updated infrequently. For up-to-date information, please visit the new OCaml website at

Browse thread
saving/loading Raw to/from file
[ Home ] [ Index: by date | by threads ]
[ Search: ]

[ Message by date: previous | next ] [ Message in thread: previous | next ] [ Thread: previous | next ]
Date: 2007-10-15 (21:28)
From: Jacques Garrigue <garrigue@m...>
Subject: Re: [Caml-list] saving/loading Raw to/from file
From: "Orlin Grigorov" <>

> With "GlPix.to_raw image" I can make the it raw, if that will help.
> The question is, I really need a way to save this "image" in a file, and be
> able to recreate it.

Once it is raw, you can read it with
   Raw.gets_string raw ~pos:0 ~len:(Raw.byte_size raw)

You can read it back in the same way:
   let raw = Raw.create `ubyte ~len:(w*h*4) in
   Raw.sets_string raw ~pos:0 ~len:(w*h*4) s;
   GlPix.of_raw raw ~format:`rgba ~width:w ~height:h

This should be efficient enough.
Once you get a string, you know how to do the I/O.

Jacques Garrigue