i am trying to copy the pixels of a Bitmap into a DirectX texture. its simple to get the IntPtr's from both, but how do i copy the pixel data efficiently?
var data = FBitmap.LockBits(..)
var rect = texture.LockRectangle(0, LockFlags.None);
IntPtr from = data.Scan0;
IntPtr to = rect.Data.DataPointer;
//copy data
texture.UnlockRectangle(0);
FBitmap.UnlockBits(data);
i tried to use Marshal.Copy but it need the pixels as an array and i would like to avoid another copy of course.
If you're talking about the kind of bleeding edge efficiency where every CPU cycle counts, you're better off just using the data pointer directly with unsafe
code.
There's no real fast way to map a flat array over an actual managed object like Array
, you'd have to copy the pixel data byte by byte pretty much.
You could use the Windows API CopyMemory - Alias "RtlMoveMemory". Much faster than all of that LockBits stuff...
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.