Changing location of GetTexture to extensions

This commit is contained in:
Nathan Adams
2012-05-18 21:35:58 -05:00
parent fa897881c3
commit 2ffb70d9fc
6 changed files with 53 additions and 33 deletions

View File

@@ -415,39 +415,6 @@ namespace Axios.Engine
return true;
}
#if WINDOWS
// System.Drawing is NOT avaiable on WP7 or Xbox
/*
* http://stackoverflow.com/a/7394185/195722
*
*
*
*/
public Texture2D GetTexture(System.Drawing.Bitmap bitmap)
{
BlendState oldstate = ScreenManager.GraphicsDevice.BlendState;
ScreenManager.GraphicsDevice.BlendState = BlendState.AlphaBlend;
Texture2D tex = new Texture2D(this.ScreenManager.GraphicsDevice, bitmap.Width, bitmap.Height, true, SurfaceFormat.Color);
System.Drawing.Imaging.BitmapData data = bitmap.LockBits(new System.Drawing.Rectangle(0, 0, bitmap.Width, bitmap.Height), System.Drawing.Imaging.ImageLockMode.ReadOnly, bitmap.PixelFormat);
int bufferSize = data.Height * data.Stride;
//create data buffer
byte[] bytes = new byte[bufferSize];
// copy bitmap data into buffer
System.Runtime.InteropServices.Marshal.Copy(data.Scan0, bytes, 0, bytes.Length);
// copy our buffer to the texture
tex.SetData(bytes);
// unlock the bitmap data
bitmap.UnlockBits(data);
this.ScreenManager.GraphicsDevice.BlendState = oldstate;
return tex;
}
#endif
}
}