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


C# Texture.CreateFromBitmap方法代码示例

本文整理汇总了C#中Texture.CreateFromBitmap方法的典型用法代码示例。如果您正苦于以下问题:C# Texture.CreateFromBitmap方法的具体用法?C# Texture.CreateFromBitmap怎么用?C# Texture.CreateFromBitmap使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在Texture的用法示例。


在下文中一共展示了Texture.CreateFromBitmap方法的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: Import

        public override Asset Import(string path)
        {
            Texture texture = new Texture();
            texture.FileName = path;

            PIX pix = PIX.Load(path);
            texture.CreateFromBitmap(pix.Pixies[0].GetBitmap(), pix.Pixies[0].Name);

            return texture;
        }
开发者ID:DevilboxGames,项目名称:Flummery,代码行数:10,代码来源:PIXImporter.cs

示例2: Import

        public override Asset Import(string path)
        {
            var img = IMG.Load(path);
            Texture texture = new Texture();

            texture.CreateFromBitmap(img.ExportToBitmap(), Path.GetFileNameWithoutExtension(path));
            texture.FileName = path;

            return texture;
        }
开发者ID:DevilboxGames,项目名称:Flummery,代码行数:10,代码来源:IMGImporter.cs

示例3: Import

        public override Asset Import(string path)
        {
            Texture texture = new Texture();

            texture.FileName = path;

            using (var bitmap = new Bitmap(path)) { texture.CreateFromBitmap(bitmap, Path.GetFileNameWithoutExtension(path)); }

            return texture;
        }
开发者ID:DevilboxGames,项目名称:Flummery,代码行数:10,代码来源:BMPImporter.cs

示例4: Import

        public override Asset Import(string path)
        {
            Texture texture = new Texture();

            texture.FileName = path;

            var fi = new FileInfo(path);
            using (var bitmap = new Bitmap(path)) { texture.CreateFromBitmap(bitmap, fi.Name.Replace(fi.Extension, "")); }

            return texture;
        }
开发者ID:DevilboxGames,项目名称:Flummery,代码行数:11,代码来源:PNGImporter.cs

示例5: Import

        public override Asset Import(string path)
        {
            Texture texture = new Texture();
            texture.FileName = path;

            if (string.Compare(Path.GetExtension(path), ".tif", true) == 0)
            {
                using (var bitmap = new Bitmap(path)) { texture.CreateFromBitmap(bitmap, Path.GetFileNameWithoutExtension(path)); }
            }
            else
            {
                texture = (Texture)(new PIXImporter()).Import(path);
            }

            return texture;
        }
开发者ID:DevilboxGames,项目名称:Flummery,代码行数:16,代码来源:TIFImporter.cs

示例6: ImportMany

        public override AssetList ImportMany(string path)
        {
            TextureList textures = new TextureList();

            var pix = PIX.Load(path);

            foreach (var pixelmap in pix.Pixies)
            {
                Texture texture = new Texture();

                texture.CreateFromBitmap(pixelmap.GetBitmap(), pixelmap.Name);

                textures.Entries.Add(texture);
            }

            //texture.SetData(tdx.Name, tdx.Format.ToString(), tdx.MipMaps[0].Width, tdx.MipMaps[0].Height, tdx.MipMaps[0].Data);
            //texture.SupportingDocuments["Source"] = tdx;
            //texture.FileName = path;

            return textures;
        }
开发者ID:DevilboxGames,项目名称:Flummery,代码行数:21,代码来源:PIXImporter.cs

示例7: Import

        public override Asset Import(string path)
        {
            Texture texture = new Texture();

            texture.FileName = path;

            var fi = new FileInfo(path);

            using (var br = new BinaryReader(fi.OpenRead()))
            {
                byte idLength = br.ReadByte();
                byte colourMapType = br.ReadByte();
                byte imageType = br.ReadByte();

                if (idLength > 0) { throw new NotImplementedException("No support for TGA files with ID sections!"); }
                if (colourMapType == 0) { br.ReadBytes(5); } else { throw new NotImplementedException("No support for TGA files with ColourMaps!"); }

                int xOrigin = br.ReadInt16();
                int yOrigin = br.ReadInt16();
                int width = br.ReadInt16();
                int height = br.ReadInt16();
                byte pixelDepth = br.ReadByte();
                byte imageDescriptor = br.ReadByte();

                using (var bmp = new Bitmap(width, height, PixelFormat.Format32bppArgb))
                {
                    BitmapData bmpdata;
                    PixelFormat format = PixelFormat.Format32bppArgb;
                    byte size = (byte)(pixelDepth / 8);

                    if (size == 3) { format = PixelFormat.Format24bppRgb; }

                    bmpdata = bmp.LockBits(new Rectangle(0, 0, width, height), ImageLockMode.ReadWrite, format);

                    if (imageType == 10)
                    {
                        const int iRAWSection = 127;
                        uint j = 0;
                        int iStep = 0;
                        int bpCount = 0;
                        int currentPixel = 0;
                        int pixelCount = width * height;
                        var colorBuffer = new byte[size];
                        byte chunkHeader = 0;
                        byte[] buffer = br.ReadBytes((int)br.BaseStream.Length - 13);

                        using (var nms = new MemoryStream())
                        {
                            while (currentPixel < pixelCount)
                            {
                                chunkHeader = buffer[iStep];
                                iStep++;

                                if (chunkHeader <= iRAWSection)
                                {
                                    chunkHeader++;
                                    bpCount = size * chunkHeader;
                                    nms.Write(buffer, iStep, bpCount);
                                    iStep += bpCount;

                                    currentPixel += chunkHeader;
                                }
                                else
                                {
                                    chunkHeader -= iRAWSection;
                                    Array.Copy(buffer, iStep, colorBuffer, 0, size);
                                    iStep += size;
                                    for (j = 0; j < chunkHeader; j++) { nms.Write(colorBuffer, 0, size); }
                                    currentPixel += chunkHeader;
                                }
                            }

                            var contentBuffer = new byte[nms.Length];
                            nms.Position = 0;
                            nms.Read(contentBuffer, 0, contentBuffer.Length);

                            Marshal.Copy(contentBuffer, 0, bmpdata.Scan0, contentBuffer.Length);
                        }
                    }
                    else
                    {
                        Marshal.Copy(br.ReadBytes(width * height * size), 0, bmpdata.Scan0, width * height * size);
                    }

                    bmp.UnlockBits(bmpdata);

                    texture.CreateFromBitmap(bmp, Path.GetFileNameWithoutExtension(path));
                }
            }

            return texture;
        }
开发者ID:DevilboxGames,项目名称:Flummery,代码行数:92,代码来源:TGAImporter.cs


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