当前位置: 首页>>代码示例>>C#>>正文


C# Texture.GetWidth方法代码示例

本文整理汇总了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;
 }
开发者ID:jikoriko,项目名称:OpentkEngine,代码行数:10,代码来源:Sprite.cs

示例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;
        }
开发者ID:tjhorner,项目名称:gtaivtools,代码行数:48,代码来源:TextureDecoder.cs

示例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));
        }
开发者ID:jamesburton,项目名称:AndEngine.net,代码行数:24,代码来源:Font.cs

示例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);
        }
开发者ID:jikoriko,项目名称:OpentkEngine,代码行数:21,代码来源:Graphics.cs

示例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);
        }
开发者ID:tjhorner,项目名称:gtaivtools,代码行数:88,代码来源:TextureEncoder.cs


注:本文中的Texture.GetWidth方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。