Using native pointers in F # with WritableBitmap

Hi

I am trying to use WritableBitmap.BackBufferas used in this example , see section examples.
What I'm trying to do is write int[]a space a nativeint.

To be able to write from int [] to some memory, I started with this answer on SO. Microsoft.FSharp.NativeInterop.NativePtr.writeseems like a good feature to record.

After trying to read and read a bit two questions arise.

  • WritableBitmap.BackBufferis of type native, how to convert to nativeptr that it wants NativePter.write?

  • It seems that I can write only one intat a time, but I want to write a whole int [].

I admit that I am in deep water, but in deep water you learn to swim :)

Thanks in advance Gorgen

+3
source share
2 answers

I think that a function NativePtr.writecan only be used to write one value at a time, so if you want to copy an array, you have to use a loop for.

A simpler option would be to use a method Marshal.Copy( see MSDN ), which takes the original array (there are overloads for arrays containing elements of various types) and intptras the destination.

Something like this should work:

let imageData = [| ... |] // generate one dimensional array with image data
writeableBitmap.Lock()

let buffer = writeableBitmap.BackBuffer
Marshal.Copy(imageData, 0, buffer, imageData.Length)
+3
source

, . , , nativeint nativeptr NativeInterop.NativePtr.ofNativeInt.

+4

Source: https://habr.com/ru/post/1776243/


All Articles