smourier/WicNet

how to use copypixels to get a pixel value in WIC ?

Closed this issue · 4 comments

how to use copypixels to get a pixel value in WIC ?

https://learn.microsoft.com/en-us/windows/win32/api/wincodec/nf-wincodec-iwicbitmapsource-copypixels

Can you provide a sample code?

Getting a pixel depends on the pixel format of the WIC bitmap source.

There are various examples here for example https://github.com/smourier/WicNet/blob/main/WicNet.Tests/Program.cs#L59

Getting a pixel depends on the pixel format of the WIC bitmap source.

There are various examples here for example https://github.com/smourier/WicNet/blob/main/WicNet.Tests/Program.cs#L59

var bytes = bmp.CopyPixels(); --- it is slowly

HRESULT CopyPixels(
[in] const WICRect *prc,
[in] UINT cbStride,
[in] UINT cbBufferSize,
[out] BYTE *pbBuffer
);

how to set WICRect ?
i use it in mousemove event , so I need a quick method to read the pixel values of the specified coordinates

thanks for your help.

WicNet's CopyPixels has multiple overloads, for example

public void CopyPixels(int left, int top, int width, int height, uint bufferSize, IntPtr buffer, int? stride = null)

here
https://github.com/smourier/WicNet/blob/main/WicNet/WicBitmapSource.cs#L268

which maps to the native method with a rectangle

thanks a lot