2015-04-04 41 views
0

随着CamlImages,我怎么可以找到一个点的颜色OCaml的工件坐标XY与JPEG

let() = 
    let name = "test.jpg" in 
    let image = Jpeg.load name [] in 

形象键入Images.t

,但有趣的Rgb24.get requred型Rgb24.t

(* get color from coords XY *) 
    let x = 1 and y = 1 in 
    let rgb = Rgb24.get image x y in 
    print_int rgb.r; 

我尝试了所有的功能,从库,但没有找到解决办法。

回答

3

Jpeg.load回报Images.t,其定义是:

type t = 
    | Index8 of Index8.t 
    | Rgb24 of Rgb24.t 
    | Index16 of Index16.t 
    | Rgba32 of Rgba32.t 
    | Cmyk32 of Cmyk32.t;; 

所有你需要的是模式匹配的Jpeg.load结果,并得到Rgb24.t

let rgb24 = match Jpeg.load name [] with 
    | Rgb24 x -> x 
    | _ -> failwith "image must be rgb24" 
+0

非常感谢您的帮助。 – 2015-04-04 09:26:04