本文整理汇总了C#中Texture.GetWidth方法的典型用法代码示例。如果您正苦于以下问题:C# Texture.GetWidth方法的具体用法?C# Texture.GetWidth怎么用?C# Texture.GetWidth使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Texture
的用法示例。
在下文中一共展示了Texture.GetWidth方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: Sprite
public Sprite(Texture spriteSheet, int xFrames, int yFrames)
{
xFrames = xFrames < 1 ? 1 : xFrames;
yFrames = yFrames < 1 ? 1 : yFrames;
this.SpriteSheet = spriteSheet;
this._xFrames = xFrames;
this._yFrames = yFrames;
this._spriteWidth = spriteSheet.GetWidth() / xFrames;
this._spriteHeight = spriteSheet.GetHeight() / yFrames;
}
示例2: Decode
internal static Image Decode(Texture texture, int level)
{
var width = texture.GetWidth(level);
var height = texture.GetHeight(level);
var data = texture.GetTextureData(level);
switch(texture.TextureType)
{
case TextureType.DXT1:
data = DXTDecoder.DecodeDXT1(data, (int)width, (int)height);
break;
case TextureType.DXT3:
data = DXTDecoder.DecodeDXT3(data, (int)width, (int)height);
break;
case TextureType.DXT5:
data = DXTDecoder.DecodeDXT5(data, (int)width, (int)height);
break;
case TextureType.A8R8G8B8:
// Nothing to do, the data is already in the format we want it to be
break;
case TextureType.L8:
{
var newData = new byte[data.Length*4];
for (int i = 0; i < data.Length; i++)
{
newData[i*4 + 0] = data[i];
newData[i*4 + 1] = data[i];
newData[i*4 + 2] = data[i];
newData[i*4 + 3] = 255;
}
data = newData;
}
break;
default:
throw new ArgumentOutOfRangeException();
}
var bmp = new Bitmap((int) width, (int) height, PixelFormat.Format32bppArgb);
var rect = new Rectangle(0, 0, (int) width, (int) height);
var bmpdata = bmp.LockBits(rect, ImageLockMode.WriteOnly, PixelFormat.Format32bppArgb);
Marshal.Copy(data, 0, bmpdata.Scan0, (int) width*(int) height*4);
bmp.UnlockBits(bmpdata);
return bmp;
}
示例3: Font
// ===========================================================
// Constructors
// ===========================================================
public Font(Texture pTexture, Typeface pTypeface, float pSize, bool pAntiAlias, int pColor)
{
this.mTexture = pTexture;
this.mTextureWidth = pTexture.GetWidth();
this.mTextureHeight = pTexture.GetHeight();
this.mPaint = new Paint();
this.mPaint.SetTypeface(pTypeface);
this.mPaint.Color = pColor;
this.mPaint.TextSize = pSize;
this.mPaint.AntiAlias = pAntiAlias;
this.mBackgroundPaint = new Paint();
this.mBackgroundPaint.Color = Color.Transparent;
this.mBackgroundPaint.SetStyle(Style.Fill);
this.mFontMetrics = this.mPaint.GetFontMetrics();
this.mLineHeight = (int)FloatMath.Ceil(Math.Abs(this.mFontMetrics.Ascent) + Math.Abs(this.mFontMetrics.Descent));
this.mLineGap = (int)(FloatMath.Ceil(this.mFontMetrics.Leading));
}
示例4: DrawTexture
public static void DrawTexture(Texture texture, float x, float y, float z, float width, float height, int sx, int sy, int sw, int sh, Color4 color)
{
float textX = (float)sx / texture.GetWidth();
float textY = (float)sy / texture.GetHeight();
float textW = (float)sw / texture.GetWidth();
float textH = (float)sh / texture.GetHeight();
if (textX != _texturePosition.X || textY != _texturePosition.Y || textW != _textureDimension.X || textH != _textureDimension.Y)
{
_texturePosition.X = textX;
_texturePosition.Y = textY;
_textureDimension.X = textW;
_textureDimension.Y = textH;
_texCoordsChanged = true;
}
texture.Bind();
SetColor(color);
RenderQuad(x, y, z, width, height);
}
示例5: Encode
internal static void Encode(Texture texture, Image image, int level)
{
var width = texture.GetWidth(level);
var height = texture.GetHeight(level);
var data = new byte[width * height * 4]; // R G B A
var bitmap = new Bitmap((int)width, (int)height);
Graphics g = Graphics.FromImage(bitmap);
g.InterpolationMode = InterpolationMode.HighQualityBilinear;
g.DrawImage(image, 0, 0, (int)width, (int)height);
g.Dispose();
var rect = new Rectangle(0, 0, (int) width, (int) height);
BitmapData bmpdata = bitmap.LockBits(rect, ImageLockMode.ReadOnly, PixelFormat.Format32bppArgb);
if (texture.TextureType == TextureType.A8R8G8B8)
{
Marshal.Copy(bmpdata.Scan0, data, 0, (int) width*(int) height*4);
}
else if (texture.TextureType == TextureType.L8)
{
var newData = new byte[width * height];
// Convert to L8
unsafe
{
var p = (byte*)bmpdata.Scan0;
for (var y = 0; y < bitmap.Height; y++)
{
for (var x = 0; x < bitmap.Width; x++)
{
var offset = y * bmpdata.Stride + x * 4;
var dataOffset = y * width + x;
newData[dataOffset] = (byte)((p[offset + 2] + p[offset + 1] + p[offset + 0])/3);
}
}
}
data = newData;
}
else
{
// Convert from the B G R A format stored by GDI+ to R G B A
unsafe
{
var p = (byte*)bmpdata.Scan0;
for (var y = 0; y < bitmap.Height; y++)
{
for (var x = 0; x < bitmap.Width; x++)
{
var offset = y * bmpdata.Stride + x * 4;
var dataOffset = y * width * 4 + x * 4;
data[dataOffset + 0] = p[offset + 2]; // R
data[dataOffset + 1] = p[offset + 1]; // G
data[dataOffset + 2] = p[offset + 0]; // B
data[dataOffset + 3] = p[offset + 3]; // A
}
}
}
}
bitmap.UnlockBits(bmpdata);
bitmap.Dispose();
switch (texture.TextureType)
{
case TextureType.DXT1:
data = DXTEncoder.EncodeDXT1(data, (int) width, (int) height);
break;
case TextureType.DXT3:
data = DXTEncoder.EncodeDXT3(data, (int) width, (int) height);
break;
case TextureType.DXT5:
data = DXTEncoder.EncodeDXT5(data, (int) width, (int) height);
break;
case TextureType.A8R8G8B8:
case TextureType.L8:
// Nothing to do
break;
default:
throw new ArgumentOutOfRangeException();
}
texture.SetTextureData(level, data);
}