Changing location of GetTexture to extensions
This commit is contained in:
parent
fa897881c3
commit
2ffb70d9fc
@ -166,6 +166,7 @@
|
|||||||
<Compile Include="Engine\Data\AxiosDataTable.cs" />
|
<Compile Include="Engine\Data\AxiosDataTable.cs" />
|
||||||
<Compile Include="Engine\DrawableAxiosGameObject.cs" />
|
<Compile Include="Engine\DrawableAxiosGameObject.cs" />
|
||||||
<Compile Include="Engine\DrawableBreakableAxiosGameObject.cs" />
|
<Compile Include="Engine\DrawableBreakableAxiosGameObject.cs" />
|
||||||
|
<Compile Include="Engine\Extensions\Bitmap.cs" />
|
||||||
<Compile Include="Engine\Extensions\Contact.cs" />
|
<Compile Include="Engine\Extensions\Contact.cs" />
|
||||||
<Compile Include="Engine\Extensions\String.cs" />
|
<Compile Include="Engine\Extensions\String.cs" />
|
||||||
<Compile Include="Engine\Extensions\Texture2D.cs" />
|
<Compile Include="Engine\Extensions\Texture2D.cs" />
|
||||||
|
@ -209,6 +209,7 @@
|
|||||||
<Compile Include="Engine\Data\DataEvents.cs" />
|
<Compile Include="Engine\Data\DataEvents.cs" />
|
||||||
<Compile Include="Engine\DrawableAxiosGameObject.cs" />
|
<Compile Include="Engine\DrawableAxiosGameObject.cs" />
|
||||||
<Compile Include="Engine\DrawableBreakableAxiosGameObject.cs" />
|
<Compile Include="Engine\DrawableBreakableAxiosGameObject.cs" />
|
||||||
|
<Compile Include="Engine\Extensions\Bitmap.cs" />
|
||||||
<Compile Include="Engine\Extensions\Contact.cs" />
|
<Compile Include="Engine\Extensions\Contact.cs" />
|
||||||
<Compile Include="Engine\Extensions\String.cs" />
|
<Compile Include="Engine\Extensions\String.cs" />
|
||||||
<Compile Include="Engine\Extensions\Texture2D.cs" />
|
<Compile Include="Engine\Extensions\Texture2D.cs" />
|
||||||
|
@ -159,6 +159,7 @@
|
|||||||
<Compile Include="Engine\Data\DataEvents.cs" />
|
<Compile Include="Engine\Data\DataEvents.cs" />
|
||||||
<Compile Include="Engine\DrawableAxiosGameObject.cs" />
|
<Compile Include="Engine\DrawableAxiosGameObject.cs" />
|
||||||
<Compile Include="Engine\DrawableBreakableAxiosGameObject.cs" />
|
<Compile Include="Engine\DrawableBreakableAxiosGameObject.cs" />
|
||||||
|
<Compile Include="Engine\Extensions\Bitmap.cs" />
|
||||||
<Compile Include="Engine\Extensions\Contact.cs" />
|
<Compile Include="Engine\Extensions\Contact.cs" />
|
||||||
<Compile Include="Engine\Extensions\String.cs" />
|
<Compile Include="Engine\Extensions\String.cs" />
|
||||||
<Compile Include="Engine\Extensions\Texture2D.cs" />
|
<Compile Include="Engine\Extensions\Texture2D.cs" />
|
||||||
|
@ -86,6 +86,7 @@
|
|||||||
* 1.0.1.6 - 5/18/2012
|
* 1.0.1.6 - 5/18/2012
|
||||||
* - Adding cut extension - [Author: BJD]
|
* - Adding cut extension - [Author: BJD]
|
||||||
* - Adding support for custom handling of Gleed2D items
|
* - Adding support for custom handling of Gleed2D items
|
||||||
|
* - Changing location of GetTexture to extensions
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
#endregion
|
#endregion
|
||||||
|
@ -415,39 +415,6 @@ namespace Axios.Engine
|
|||||||
return true;
|
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
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
49
axios/Engine/Extensions/Bitmap.cs
Normal file
49
axios/Engine/Extensions/Bitmap.cs
Normal file
@ -0,0 +1,49 @@
|
|||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Linq;
|
||||||
|
using System.Text;
|
||||||
|
using Microsoft.Xna.Framework.Graphics;
|
||||||
|
using Microsoft.Xna.Framework;
|
||||||
|
using Microsoft.Xna.Framework.Content;
|
||||||
|
using GameStateManagement;
|
||||||
|
|
||||||
|
namespace Axios.Engine.Extensions
|
||||||
|
{
|
||||||
|
public static class Bitmap_extension
|
||||||
|
{
|
||||||
|
#if WINDOWS
|
||||||
|
// System.Drawing is NOT avaiable on WP7 or Xbox
|
||||||
|
/*
|
||||||
|
* http://stackoverflow.com/a/7394185/195722
|
||||||
|
*
|
||||||
|
*
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
public static Texture2D GetTexture(this System.Drawing.Bitmap bitmap, GameScreen gameScreen)
|
||||||
|
{
|
||||||
|
BlendState oldstate = gameScreen.ScreenManager.GraphicsDevice.BlendState;
|
||||||
|
gameScreen.ScreenManager.GraphicsDevice.BlendState = BlendState.AlphaBlend;
|
||||||
|
Texture2D tex = new Texture2D(gameScreen.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);
|
||||||
|
|
||||||
|
gameScreen.ScreenManager.GraphicsDevice.BlendState = oldstate;
|
||||||
|
return tex;
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
}
|
||||||
|
}
|
Loading…
Reference in New Issue
Block a user