Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

SharpDX - System.Drawing interoperability

Is it possible to get something drawn with default .net paint methods (System.Drawing methods) to a SharpDX Texture2D object so that i can display it as a texture? Preferably with the SharpDX Toolkit.

If yes, how?

edit: what i am trying so far:

Bitmap b = new Bitmap(100,100);
MemoryStream ms = new MemoryStream();
b.Save(ms, System.Drawing.Imaging.ImageFormat.Png);    
Texture2D tex = Texture2D.Load(g.device, ms); // crashing here
ms.Close();
like image 379
clamp Avatar asked Dec 06 '13 15:12

clamp


1 Answers

  b.Save(ms, System.Drawing.Imaging.ImageFormat.Png);    
  Texture2D tex = Texture2D.Load(g.device, ms); 

The Save() call leaves the memory stream positioned at the end of the stream. Which will confuzzle the Load() method, it can't read any data from the stream. You'll have to rewind the stream explicitly. Insert this statement between the two lines of code:

  ms.Position = 0;
like image 184
Hans Passant Avatar answered Oct 14 '22 05:10

Hans Passant