function - ImgUtil 函数和 colorAt
问题描述
我怎么解决这个问题?
使用 ImgUtil 函数和 colorAt 创建函数 makePicture: string -> figure -> int -> int -> unit 这样名称 makePicture 文件名 figure bh 创建一个名为 filename.png 的图像文件,其中图像的宽度为 b 和高度 h。在没有颜色的点(参见 colorAt),颜色必须为灰色(由 RGB 值 (128,128,128) 定义)。您可以使用此功能来测试您的任务。
解决方案
let makePicture filename figur b h =
let bmp =
//bmp = 位图
ImgUtil.init b h
(fun (x,y) ->
//x,y = 图中的位置
let c = match colourAt (x,y) figur with | None -> (128,128,128) | Some c -> c in ImgUtil.fromRgb c)
//c = 画布
let target = Filename + ".png"
do ImgUtil.toPngFile target bmp
do printfn "Wrote filbe: %s" target
推荐阅读
- python - 重新排列和聚合 numpy 矩阵中的列
- html - 我编辑了用户表列,所以 Stripe/Cashier 不起作用!有任何想法吗?
- python-3.x - Why is the output of my dictionary in a random, shuffled order as opposed to the order that I want (Python 3.8.3)?
- php - How to select row from Database by ID only once
- python - Using __init__ in OOP
- ios - 在 PageTabViewStyle (SwiftUI 2.0) 或 PageViewController/PageView (带有 UIKit 界面) 上显示部分上一个和下一个项目
- javascript - 捕获 JavaScript 迭代器的返回值
- html - 我需要使用 json 文件中的代码作为 html 文件中 img 的 src
- reactjs - 如何在 React 中将所有道具传递到一个变量中?
- haskell - Valid-by-construction 表 UI 组件数据结构与合并的单元格