You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
This repository was archived by the owner on Mar 30, 2019. It is now read-only.
The generic methods for copying the pixels of a WIC bitmap are wrong. They assume that there is one byte per pixel, and set a requirement that the native code does not have. When you have create a 32-bit (4 bytes per pixel) WIC bitmap, and then try to extract the pixels into a byte array, you'd create a width_height_bytes per pixel array and copy the data in it. However, when you do that, SharpDX complains wrongly. When you use unsafe code, everything works, as expected.
What should be changed
Remove or fix the unnecessary checks in generic CopyPixels methods:
if(size.Width*size.Height!=output.Length){thrownewArgumentException("output.Length must be equal to Width * Height");}
The generic CopyPixels(T) methods expect the array length to equal the number of pixels written and a template argument that matches the pixel format. For 32-bit images you will want to provide a buffer of type Color[] or ColorBGRA[] and length (height * width).
Sorry, it is not described in the doc, but the CopyPixels<T> methods are expecting the T generic to be the pixel type.This allow to copy pixels without specifying the stride (as the stride is automatically calculated by sizeof(T) * width) If you need to copy to a byte[] buffer, you have to use the CopyPixels(int stride, IntPtr dataPointer, int size) method (and unsafe code unfortunately). Though, we could introduce a method CopyPixels(int stride, byte[] buffer) if you need this scenario?
Well, I didn't expect this to work like in XNA. Both options would be nice - include it in the documentation or add the new method overload. I would personally prefer to have an additional method overload, that would certainly ring a bell about the other methods.
Description
The generic methods for copying the pixels of a WIC bitmap are wrong. They assume that there is one byte per pixel, and set a requirement that the native code does not have. When you have create a 32-bit (4 bytes per pixel) WIC bitmap, and then try to extract the pixels into a byte array, you'd create a width_height_bytes per pixel array and copy the data in it. However, when you do that, SharpDX complains wrongly. When you use unsafe code, everything works, as expected.
What should be changed
Remove or fix the unnecessary checks in generic CopyPixels methods:
Reproducing the problem
Setup code
What works
What doesn't, but should work
The text was updated successfully, but these errors were encountered: