开发者

copy raw pixel data in c#

开发者 https://www.devze.com 2023-04-13 07:11 出处:网络
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?

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.


You could use the Windows API CopyMemory - Alias "RtlMoveMemory". Much faster than all of that LockBits stuff...

http://www.pinvoke.net/default.aspx/urlmon/CopyMemory.html


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.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号