本文整理汇总了C#中Texture.FilterTexture方法的典型用法代码示例。如果您正苦于以下问题:C# Texture.FilterTexture方法的具体用法?C# Texture.FilterTexture怎么用?C# Texture.FilterTexture使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Texture
的用法示例。
在下文中一共展示了Texture.FilterTexture方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: LoadFromBitmap
private Texture LoadFromBitmap(Bitmap bitmap)
{
var bitmapRect = new Rectangle(0, 0, bitmap.Width, bitmap.Height);
switch (bitmap.PixelFormat)
{
case PixelFormat.Format32bppArgb:
PrecalculateAlpha(bitmap);
break;
case PixelFormat.Format24bppRgb:
bitmap = bitmap.Clone(bitmapRect, PixelFormat.Format32bppRgb);
break;
default:
throw new Exception(string.Format("Could not load bitmap with pixel format of `{0}`", bitmap.PixelFormat));
}
var bmlock = bitmap.LockBits(bitmapRect, ImageLockMode.ReadWrite, bitmap.PixelFormat);
var newTexture = new Texture(Device, bitmap.Width, bitmap.Height, 0, Usage.None, GetD3DFormat(bitmap.PixelFormat), Pool.Managed);
var textureLock = newTexture.LockRectangle(0, LockFlags.None);
textureLock.Data.WriteRange(bmlock.Scan0, bmlock.Height * bmlock.Stride);
bitmap.UnlockBits(bmlock);
newTexture.UnlockRectangle(0);
newTexture.FilterTexture(0, Filter.Default);
return newTexture;
}
示例2: LoadFromBitmap
private Texture LoadFromBitmap(Bitmap bitmap)
{
var bmlock = bitmap.LockBits(new System.Drawing.Rectangle(0, 0, bitmap.Width, bitmap.Height),
ImageLockMode.ReadWrite, bitmap.PixelFormat);
Debug.Assert(bmlock.PixelFormat == PixelFormat.Format32bppArgb, "Invalid pixel format");
Debug.Assert(bmlock.Stride == bmlock.Width * sizeof(RgbaColor), "Invalid pixel stride");
var ptr = (byte*) bmlock.Scan0.ToPointer();
for (var y = 0; y < bmlock.Height; y++)
{
for (var x = 0; x < bmlock.Width; x++)
{
// premultiply!
var color = (RgbaColor*)(ptr + (y * bmlock.Stride) + (x * sizeof(RgbaColor)));
var alphaFloat = (*color).Alpha/255.0f;
(*color).Red = Convert.ToByte(alphaFloat * (*color).Red);
(*color).Green = Convert.ToByte(alphaFloat * (*color).Green);
(*color).Blue = Convert.ToByte(alphaFloat * (*color).Blue);
}
}
var newTexture = new Texture(_device, bitmap.Width, bitmap.Height, 0,
Usage.None, GetD3DFormat(bitmap.PixelFormat), Pool.Managed);
var textureLock = newTexture.LockRectangle(0, LockFlags.None);
textureLock.Data.WriteRange(bmlock.Scan0, bmlock.Height * bmlock.Stride);
bitmap.UnlockBits(bmlock);
newTexture.UnlockRectangle(0);
newTexture.FilterTexture(0, Filter.Default);
return newTexture;
}