本文整理汇总了C#中System.Drawing.Bitmap.ToTexture方法的典型用法代码示例。如果您正苦于以下问题:C# System.Drawing.Bitmap.ToTexture方法的具体用法?C# System.Drawing.Bitmap.ToTexture怎么用?C# System.Drawing.Bitmap.ToTexture使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类System.Drawing.Bitmap
的用法示例。
在下文中一共展示了System.Drawing.Bitmap.ToTexture方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: CreateAutotile
/// <summary>
/// Creates an internal texture used for blit operations from the autotile graphic.
/// </summary>
/// <param name="filename">Filename of the autotile graphic</param>
/// <returns>A 48 element array of <see cref="Texture2D"/> objects.</returns>
public Texture2D[] CreateAutotile(string filename)
{
const int w = Constants.TILESIZE;
const int hw = Constants.TILESIZE / 2;
var data = new Texture2D[48];
var autotile = Cache.Autotile(filename);
if (autotile == null)
return data;
int x, y, num, index, sx, sy;
SysRect destRect, srcRect;
for (var frame = 0; frame < (autotile.Width / 96); frame++)
{
using (var template = new Bitmap(256, 192))
{
for (var lvl = 0; lvl < 6; lvl++)
{
for (var j = 0; j < 8; j++)
{
using (var g = Graphics.FromImage(template))
{
foreach (var number in _autoindex[8 * lvl + j])
{
num = number - 1;
x = 16 * (num % 6);
y = 16 * (num / 6);
srcRect = new SysRect(x + (frame * 96), y, hw, hw);
destRect = new SysRect(w * j + x % w, w * lvl + y % w, hw, hw);
g.DrawImage(autotile, destRect, srcRect, System.Drawing.GraphicsUnit.Pixel);
}
}
index = 8 * lvl + j;
using (var b = new Bitmap(w, w))
{
sx = w * (index % 8);
sy = w * (index / 8);
srcRect = new SysRect(sx, sy, w, w);
using (var g = Graphics.FromImage(b))
g.DrawImage(template, new SysRect(0, 0, w, w), srcRect, System.Drawing.GraphicsUnit.Pixel);
data[index] = b.ToTexture(GraphicsDevice);
}
}
}
}
}
return data;
}