-
Notifications
You must be signed in to change notification settings - Fork 86
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
IWICBitmapSource.CopyPixels last parameter should allow byte*
and/or Span<byte>
#909
Comments
Are you actually seeing a failure here, or is this just a speculative concern? I see the generated method is: void CopyPixels(winmdroot.Graphics.Imaging.WICRect* prc, uint cbStride, uint cbBufferSize, [Out] [MarshalAs(UnmanagedType.LPArray,SizeParamIndex = 2)] byte[] pbBuffer); This looks correct to me, since the documentation for this method shows the user should allocate the array and then pass its length in as the 3rd parameter so the native side knows the length of the array. The native function can write to the array as documented, then you can read it afterward. So I don't see the problem. That said, I am actually a bit surprised that the original method uses |
It is just a speculative concern. |
I've never used this function myself and generally this repo can't provide guidance for individual functions. General purpose win32 forums would be better for that. Although you can try using the Discussions tab to ask other community members about how to use |
I think you are right, that there is no defect here. But for a performance standpoint I think it will be better to have a byte* for the last parameter. If you want to create a System.Drawing.Bitmap from this function you can do this uint stride, bufferSize;
IWICBitmap wicBitmap;
uint width, height;
//fill stride, bufferSize from some WIC functions I do not know yet, create the wicBitmap
wicBitmap.GetSize(out width, out height);
Bitmap alpha = new Bitmap((int)width, (int)height, PixelFormat.Format32bppArgb);
BitmapData alphaData = alpha.LockBits(new Rectangle(new Point(), alpha.Size), ImageLockMode.ReadWrite, alpha.PixelFormat);
wicBitmap.CopyPixels(null, stride, bufferSize, (byte*)alphaData.Scan0);
alpha.UnlockBits(alphaData); If you only have the byte[], you have to do a Marshal.Copy to copy the byte[] to alphaData.Scan0. In this case you have two marshalling functions. |
byte*
and/or Span<byte>
As a workaround for now, for performance intensive applications consider setting |
So I did a little more research into this. I wanted to get back to a So I think we'll have to keep the |
Actual behavior
HRESULT Windows.Win32.Graphics.Imaging.IWICBitmapSource.CopyPixels(WICRect* prc, uint cbStride, uint cbBufferSize, byte[] pbBuffer).
I think the byte array is wrong here, because the user have no information about the size of the array before calling CopyPixels.
Also the extended versions for this call seems to be wrong.
Expected behavior
unsafe HRESULT Windows.Win32.Graphics.Imaging.IWICBitmapSource.CopyPixels(WICRect* prc, uint cbStride, uint cbBufferSize, byte* pbBuffer).
Repro steps
NativeMethods.txt
content:NativeMethods.json
content (if present):Context
netstandard2.0
]LangVersion
(if explicitly set by project): [e.g.9
]The text was updated successfully, but these errors were encountered: