Gor*_*gen 2 f# image-manipulation
我通过将C#中的程序转换为F#来学习F#
问题在于WritableBitmap,编译器抱怨:
The type tableBitmap is not defined
这是代码:
module MandelbrotBitmap
open System.Windows.Media
open System.Windows.Media.Imaging
type Mandelbrot(width:int) as this =
let mutable _width = width
let mutable _height = 10
let mutable bitmap = new WritableBitmap( _width, _heights, 96.0, 96.0,
PixelFormats.Bgr32, None)
member this.Width
with get() = _width
and set(newVal) = _width <- newVal
Run Code Online (Sandbox Code Playgroud)
将None在instanciation是我尝试更换null原表达.
我PresentationCore和WindowsBase我的参考资料.
bitmap = new WriteableBitmap(
(int)sizeInfo.NewSize.Width,
(int)sizeInfo.NewSize.Height,
96, 96, PixelFormats.Bgr32, null);
Run Code Online (Sandbox Code Playgroud)
这篇msdn文章描述了WriteableBitmap
我的问题是; 什么是编译器抱怨?
你有两个拼写错误:WritableBitmap应该是WriteableBitmap,_heights应该是_ height.此外,null并且None不可互换,当您使用.NET框架类时,您必须经常使用null,这是F#的互操作功能.最后一个问题,如果你想在WriteableBitmap构造函数中的行之间拆分你的参数,你需要确保下一行是缩进的,new因为空格在F#中很重要.这是最终的,固定的WriteableBitmap构造函数调用:
new WriteableBitmap( _width, _height, 96.0, 96.0,
PixelFormats.Bgr32, null)
Run Code Online (Sandbox Code Playgroud)