⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 gxbitmap.cs

📁 功能:基于windows mobile 的地图查看器。使用vs2005开发
💻 CS
字号:
using System;
using System.IO;
using System.Drawing;
using System.Runtime.InteropServices;
using System.Windows.Forms;

#if !DESKTOP
using Microsoft.WindowsMobile.DirectX;
using Microsoft.WindowsMobile.DirectX.Direct3D;
#else
using Microsoft.DirectX;
using Microsoft.DirectX.Direct3D;
#endif

namespace GXGraphicsLibrary
{

	public interface IGXBitmap : IDisposable
	{
		Color SourceKey { get; }
		int Width { get; }
		int Height { get; }
	}

	/// <summary>
	/// Summary description for GXBitmap.
	/// </summary>
	public class GDIGXBitmap : IGXBitmap
	{
		/// <summary>
		/// Access the internal GDI representation of the Bitmap object
		/// </summary>
		internal Bitmap Image { get { return m_bmp; } }

		/// <summary>
		/// Get the color of the images source key.
		/// </summary>
		public Color SourceKey { get { return m_sourceKey; } }
		Color m_sourceKey = Color.Empty;

		/// <summary>
		/// True if the image should be drawn with alpha transparency
		/// </summary>
		public bool Transparent { get { return TransparentValue; } }
		bool TransparentValue = false;

		/// <summary>
		/// Internal GDI representation of the image.
		/// </summary>
		protected Bitmap m_bmp = null;

		/// <summary>
		/// Get the width of this image.
		/// </summary>
		public int Width { get { return m_bmp.Width; } }

		/// <summary>
		/// Get the height of this image.
		/// </summary>
		public int Height { get { return m_bmp.Height; } }

		/// <summary>
		/// Allocate and load an image from the specified file.
		/// </summary>
		/// <param name="fileName">Name of image file</param>
		public GDIGXBitmap(string fileName, bool transparent)
		{
			m_bmp = new Bitmap(fileName);
			if(transparent)
			  m_sourceKey = m_bmp.GetPixel(0,0);
		}

		/// <summary>
		/// Free any resources allocated for the image.
		/// </summary>
		public void Dispose()
		{
			m_bmp.Dispose();
		}
	}

	/// <summary>
	/// Summary description for GXBitmap.
	/// </summary>
	public class DirectXGXBitmap : IGXBitmap
	{

		/// <summary>
		/// True if the image should be drawn with alpha transparency
		/// </summary>
		public bool Transparent { get { return TransparentValue; } }
		bool TransparentValue;

		/// <summary>
		/// Get the color of the images source key.
		/// </summary>
		public Color SourceKey { get { return m_sourceKey; } }
		Color m_sourceKey = Color.Empty;

		/// <summary>
		/// The original width of the image
		/// </summary>
		protected int width;

		/// <summary>
		/// The original height of the image
		/// </summary>
		protected int height;

		/// <summary>
		/// The texture object holding this image
		/// </summary>
		protected Texture m_tex;

		public Texture Texture { get { return m_tex; } }

		/// <summary>
		/// Get the width of this image.
		/// </summary>
		public int Width { get { return width; } }

		/// <summary>
		/// Get the height of this image.
		/// </summary>
		public int Height { get { return height; } }

		/// <summary>
		/// Allocate and load an image from the specified file.
		/// </summary>
		/// <param name="fileName">Name of image file</param>
		/// <param name="transparent">True if the image should have transparency</param>
		public DirectXGXBitmap(string fileName, Device dev, bool transparent)
		{
			Bitmap m_bmp = new Bitmap(fileName);
			width = m_bmp.Width;
			height = m_bmp.Height;
			if(transparent)
			  m_sourceKey = m_bmp.GetPixel(0,0);
			TransparentValue = transparent;
			m_bmp.Dispose();
			m_bmp = null;

#if DESKTOP
			Format format = Format.A8R8G8B8;
			Pool pool = Pool.Default;
#else
			Format format = Format.A1R5G5B5;
			Pool pool = Pool.VideoMemory;
#endif
			m_tex = TextureLoader.FromFile(dev, fileName, Width, Height, 1, 
				    Usage.None, format, pool, Filter.Linear, Filter.None, SourceKey.ToArgb());
		} 

		/// <summary>
		/// Free any resources allocated for the image.
		/// </summary>
		public void Dispose()
		{
			if(m_tex != null)
			{
				m_tex.Dispose();
				m_tex = null;
			}

		}


	}
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -