Original Post
I code in C#. I am trying to load a texture from a dynamically created 1201x1201 RGB bitmap. I first tried to load texture in most standard way, which takes about 2 minutes to complete(!?):
texture = Texture.FromBitmap(device, bmp, 0, Pool.Managed);
I then tried to do it using memory stream, but it is equaly slow(!?!?):
MemoryStream stream = new MemoryStream();
bmp.Save(stream, System.Drawing.Imaging.ImageFormat.Bmp);
bmp.Dispose();
stream.Position = 0;
texture = Texture.FromStream(device, stream, Usage.Dynamic, Pool.Managed);
And finally, I tried to do it using unsafe code, but it generates the error.
texture = new Texture(dev, bmp.Width, bmp.Height, 1, Usage.Dynamic, Format.R8G8B8, Pool.Default);
Microsoft.DirectX.GraphicsStream a = tekstura.LockRectangle(0, LockFlags.None);
System.Drawing.Imaging.BitmapData bd = bmp.LockBits(new System.Drawing.Rectangle(0, 0, bmp.Width, bmp.Height), System.Drawing.Imaging.ImageLockMode.ReadOnly, System.Drawing.Imaging.PixelFormat.Format24bppRgb);
unsafe
{
uint* to = (uint*)a.InternalDataPointer;
uint* from = (uint*)bd.Scan0.ToPointer();
for (int i = 0; i < bd.Height * bd.Width; ++i) to = from;
}
texture.UnlockRectangle(0);
bmp.UnlockBits(bd);