(* ocamlfind ocamlc -package lablgtk2 graphics -I . -c imagefromfile.ml ocamlfind ocamlc graphics.cma -package lablgtk2 -linkpkg -w s imgfromfile.ml -o imgfromfile #require "graphics";; #require "lablgtk2";; *) open Gpointer;; let locale = GtkMain.Main.init ();; let image_from_file string name = let pixb = GdkPixbuf.from_file string in let gp = GdkPixbuf.get_pixels pixb in let nthpixel gp n = let x = 4 * n in let f = Gpointer.get_byte gp in Graphics.rgb (f x) (f (x + 1)) (f (x + 2)), f ( x + 3) in let w = GdkPixbuf.get_width pixb in let h = GdkPixbuf.get_height pixb in print_string ("let "^name^" = [|\n"); for y = 0 to h - 1 do print_string "[|"; for x = 0 to w - 1 do let c, t = nthpixel gp (y * w + x) in print_int c; print_string ","; print_int t; print_string ";" done; print_string "|];\n"; done; print_string "|];;\n\n"; ;; let () = image_from_file Sys.argv.(1) Sys.argv.(2);;