F# lazy pixels reading

后端 未结 3 1015
终归单人心
终归单人心 2021-01-16 21:11

I want to make a lazy loading of image pixels to the 3 dimensional array of integers. For example in simple way it looks like this:

   for i=0 to Width 
             


        
3条回答
  •  南笙
    南笙 (楼主)
    2021-01-16 21:56

    As mentioned already by other comments that you can use the lazy pixel loading in the 3D array but that would just make the GetPixel operation lazy and not the memory allocation of the 3D array as the array is allocated already when you call create method of Array3D.

    If you want to make the memory allocation as well as GetPixel lazy then you can use sequences as shown by below code:

    let getPixels (bmp:Bitmap) =
      seq {
            for i = 0 to bmp.Height-1 do
                yield seq {
                                for j = 0 to bmp.Width-1 do
                                    let pixel = bmp.GetPixel(j,i)
                                    yield (pixel.R,pixel.G,pixel.B)
                           }
      }
    

提交回复
热议问题