示例#1
0
        private void button1_Click(object sender, EventArgs e)
        {
            try
            {
                using (var dlg = new OpenFileDialog())
                {
                    dlg.Filter =
                        "PNG Files (*.png)|*.png|JPEG Files (*.jpg)|*.jpg|BMP Files (*.bmp)|*.bmp|PSD Files (*.psd)|*.psd|TGA Files (*.tga)|*.tga|GIF Files (*.gif)|*.gif|All Files (*.*)|*.*";
                    if (dlg.ShowDialog() != DialogResult.OK)
                    {
                        return;
                    }

                    _fileName = dlg.FileName;

                    var bytes = File.ReadAllBytes(_fileName);

                    using (var stream = File.OpenRead(_fileName))
                    {
                        _loadedImage = ImageResult.FromStream(stream, ColorComponents.RedGreenBlueAlpha);
                    }
                    SetImage();
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show("Error", ex.Message);
            }
        }
示例#2
0
 private ImageResult LoadImage(string path)
 {
     using (var stream = File.OpenRead(path))
     {
         return(ImageResult.FromStream(stream, ColorComponents.RedGreenBlueAlpha));
     }
 }
示例#3
0
        private MeshTexture TextureFromFile(string filename, string directory, string typeName)
        {
            string resPath = directory + @"\" + filename;

            MeshTexture texture = new MeshTexture
            {
                Type = typeName,
                Path = filename
            };

            // load texture file with StbImage
            var io      = new System.IO.FileStream(resPath, System.IO.FileMode.Open);
            var resLoad = ImageResult.FromStream(io);

            int             width = resLoad.Width, height = resLoad.Height;
            ColorComponents nrComponents = resLoad.SourceComp;

            if (resLoad != null)
            {
                PixelInternalFormat format = 0;
                if (nrComponents == ColorComponents.Grey)
                {
                    format = PixelInternalFormat.CompressedRed;
                }
                else if (nrComponents == ColorComponents.RedGreenBlue)
                {
                    format = PixelInternalFormat.Rgb;
                }
                else if (nrComponents == ColorComponents.RedGreenBlueAlpha)
                {
                    format = PixelInternalFormat.Rgba;
                }

                // send necessary actions to dispatcher
                Dispatcher.ActionsQueue.Enqueue(() =>
                {
                    // load and generate the texture
                    GL.GenTextures(1, out texture.ID);

                    GL.BindTexture(TextureTarget.Texture2D, texture.ID);
                    GL.TexImage2D(TextureTarget.Texture2D, 0, format, width, height, 0, (PixelFormat)format, PixelType.UnsignedByte, resLoad.Data);
                    GL.GenerateMipmap(GenerateMipmapTarget.Texture2D);

                    // set the texture wrapping/filtering options (on the currently bound texture object)
                    GL.TexParameter(TextureTarget.Texture2D, TextureParameterName.TextureWrapS, (int)OpenTK.Graphics.OpenGL4.TextureWrapMode.Repeat);
                    GL.TexParameter(TextureTarget.Texture2D, TextureParameterName.TextureWrapT, (int)OpenTK.Graphics.OpenGL4.TextureWrapMode.Repeat);
                    GL.TexParameter(TextureTarget.Texture2D, TextureParameterName.TextureMinFilter, (int)TextureMinFilter.LinearMipmapLinear);
                    GL.TexParameter(TextureTarget.Texture2D, TextureParameterName.TextureMagFilter, (int)TextureMagFilter.Linear);
                });
            }
            else
            {
                // TODO: throw new exception, although not necessarily - it's already implemented in ImageResult.FromResult
            }

            // explicitly destroy I/O stream object
            io.Dispose();

            return(texture);
        }
示例#4
0
        /// <summary>
        /// Creates and loads and new image
        /// </summary>
        /// <param name="fileLocation">Location of the image</param>
        /// <param name="filp">Filp the image on load</param>
        /// <exception cref="FileNotFoundException"></exception>
        public Image(string fileLocation, bool filp)
        {
            if (!File.Exists(fileLocation))
            {
                throw new FileNotFoundException("Image doesn't exist!", fileLocation);
            }

            //Filp image on load, if we want to filp it
            if (filp)
            {
                StbImage.stbi_set_flip_vertically_on_load(1);
            }

            //Open stream
            FileStream imageStream = File.OpenRead(fileLocation);

            //Create image
            ImageResult image = ImageResult.FromStream(imageStream);

            Data   = image.Data;
            Width  = image.Width;
            Height = image.Height;

            //IDK if this was purposely done, but the enum number matches to the channels count of what the enum is
            Channels = (int)image.SourceComp;
        }
示例#5
0
        /// <summary> Creates a texture using anisotropic filtering, primarily meant for regular texture use. </summary>
        public Texture(string location, int uniform)
        {
            UniformLocation = uniform;

            if (LOADED_TEXTURES.ContainsKey(location))
            {
                this.TextureID = LOADED_TEXTURES[location];
            }
            else
            {
                ImageResult image;
                using (FileStream stream = File.OpenRead(location)) {
                    image = ImageResult.FromStream(stream, ColorComponents.RedGreenBlueAlpha);
                }

                float anisotropicLevel = MathHelper.Clamp(16, 1f, MaxAnisotrophy);

                TextureID = GL.GenTexture();
                GL.BindTexture(TextureTarget.Texture2D, TextureID);
                GL.TexParameter(TextureTarget.Texture2D, TextureParameterName.TextureWrapS, (int)TextureWrapMode.Repeat);
                GL.TexParameter(TextureTarget.Texture2D, TextureParameterName.TextureWrapT, (int)TextureWrapMode.Repeat);
                GL.TexParameter(TextureTarget.Texture2D, TextureParameterName.TextureMinFilter, (int)TextureMinFilter.LinearMipmapLinear);
                GL.TexParameter(TextureTarget.Texture2D, (TextureParameterName)All.TextureMaxAnisotropy, anisotropicLevel);
                GL.TexImage2D(TextureTarget.Texture2D, 0, PixelInternalFormat.Rgba,
                              image.Width, image.Height, 0, PixelFormat.Rgba, PixelType.UnsignedByte, image.Data);
                GL.GenerateMipmap(GenerateMipmapTarget.Texture2D);

                LOADED_TEXTURES.Add(location, TextureID);
            }
        }
示例#6
0
        public static Texture Load(string filename)
        {
            ImageResult image;

            using (var stream = File.OpenRead(filename))
            {
                image = ImageResult.FromStream(stream, ColorComponents.RedGreenBlueAlpha);
            }

            Texture tex = new Texture();

            tex.Width  = image.Width;
            tex.Height = image.Height;

            GL.PixelStore(PixelStoreParameter.UnpackAlignment, 1);

            GL.CreateTextures(TextureTarget.Texture2D, 1, out tex.ID);

            int[] texparam = new int[]
            {
                (int)TextureMinFilter.Linear,
                (int)TextureMagFilter.Linear
            };
            GL.TextureParameterI(tex.ID, TextureParameterName.TextureMinFilter, ref texparam[0]);
            GL.TextureParameterI(tex.ID, TextureParameterName.TextureMagFilter, ref texparam[1]);

            GL.TextureStorage2D(tex.ID, 1, SizedInternalFormat.Rgba8, image.Width, image.Height);
            GL.TextureSubImage2D(tex.ID, 0, 0, 0, image.Width, image.Height, PixelFormat.Rgba, PixelType.UnsignedByte, image.Data);

            GL.PixelStore(PixelStoreParameter.UnpackAlignment, 4);

            return(tex);
        }
示例#7
0
文件: Program.cs 项目: rds1983/Jord
        static void Main(string[] args)
        {
            if (args.Length < 2)
            {
                Console.WriteLine("Jord.FontToTextureAtlas converts BMFont to LibGDX TextureAtlas.");
                Console.WriteLine("Usage: ToMyraStylesheetConverter <input.fnt> <output.atlas>");

                return;
            }

            try
            {
                var data = new BitmapFont();
                data.Load(args[0]);

                ImageResult imageResult = null;
                using (var stream = File.OpenRead(data.Pages[0].FileName))
                {
                    imageResult = ImageResult.FromStream(stream);
                }

                using (var stream = File.OpenWrite(args[1]))
                    using (var writer = new StreamWriter(stream))
                    {
                        var page = data.Pages[0];
                        writer.WriteLine();
                        writer.WriteLine(page.FileName);
                        writer.WriteLine("size: {0},{1}", imageResult.Width, imageResult.Height);
                        writer.WriteLine("format: RGBA8888");
                        writer.WriteLine("filter: Nearest,Nearest");
                        writer.WriteLine("repeat: none");

                        var characters = data.Characters.Values.OrderBy(c => c.Char);
                        foreach (var character in characters)
                        {
                            if (character.Char <= 32 || character.Char >= 128)
                            {
                                continue;
                            }

                            var bounds = character.Bounds;

                            writer.WriteLine(character.Char.ToString());
                            writer.WriteLine("  rotate: false");
                            writer.WriteLine("  xy: {0},{1}", bounds.X, bounds.Y);
                            writer.WriteLine("  size: {0},{1}", bounds.Width, bounds.Height);
                            writer.WriteLine("  orig: {0},{1}", bounds.Width, bounds.Height);
                            writer.WriteLine("  offset: 0, 0");
                            writer.WriteLine("  index: -1");
                        }

                        writer.WriteLine();
                    }
            }
            catch (Exception ex)
            {
                Console.WriteLine(ex.ToString());
            }
        }
示例#8
0
        public static Task <ImageResult> LoadAndDispose(Stream stream)
        {
            var image = ImageResult.FromStream(stream, ColorComponents.RedGreenBlueAlpha);

            stream.Dispose();
            Conversion.stbi__vertical_flip(image.Data, image.Width, image.Height, 4);
            return(Task.FromResult(image));
        }
示例#9
0
        public static ImageResource LoadImage(string path)
        {
            using var stream = File.OpenRead(path);

            var image = ImageResult.FromStream(stream, ColorComponents.RedGreenBlueAlpha);

            return(new ImageResource(image.Data, image.Width, image.Height));
        }
示例#10
0
        public Image(string path)
        {
            using var stream = File.OpenRead(path);
            var res = ImageResult.FromStream(stream, ColorComponents.RedGreenBlueAlpha);

            this._data  = res.Data;
            this.Width  = res.Width;
            this.Height = res.Height;
        }
示例#11
0
        /// <summary>
        /// Loads the embedded image from the assembly in which this function is called.
        /// </summary>
        /// <param name="path">The path to the embedded image (relative to the .csproj).</param>
        /// <returns>The loaded image.</returns>
        public static ImageResult LoadEmbeddedImage(string path)
        {
            var assembly = Assembly.GetCallingAssembly();

            using (var stream = assembly.GetManifestResourceStream($"{assembly.GetName().Name}.{path}"))
            {
                return(ImageResult.FromStream(stream));
            }
        }
示例#12
0
        private static Packer PackImages(string[] imageFiles, int width, int height)
        {
            Console.WriteLine("Atlas Size: {0}x{1}", width, height);

            var packer = new Packer(width, height);

            foreach (var file in imageFiles)
            {
                Console.WriteLine("Processing {0}...", file);

                ImageResult image;
                using (var stream = File.OpenRead(file))
                {
                    image = ImageResult.FromStream(stream, StbImageSharp.ColorComponents.RedGreenBlueAlpha);
                }

                var imageInfo = new ImageInfo
                {
                    Path  = file,
                    Image = image
                };

                var name = Path.GetFileNameWithoutExtension(file);
                if (name.EndsWith(".9"))
                {
                    ProcessNinePatch(imageInfo);
                }

                Console.WriteLine("Size: {0}x{1}, Components: {2}", image.Width, image.Height, image.SourceComp);

                var packRectangle = packer.PackRect(image.Width, image.Height, imageInfo);

                // Double the size of the packer until the new rectangle will fit
                while (packRectangle == null)
                {
                    Packer newPacker = new Packer(packer.Width * 2, packer.Height * 2);

                    Console.WriteLine("Image didnt fit. Thus atlas size had been doubled: {0}x{1}", newPacker.Width, newPacker.Height);

                    // Place existing rectangles
                    foreach (PackerRectangle existingRect in packer.PackRectangles)
                    {
                        newPacker.PackRect(existingRect.Width, existingRect.Height, existingRect.Data);
                    }

                    // Now dispose old packer and assign new one
                    packer.Dispose();
                    packer = newPacker;

                    // Try to fit the rectangle again
                    packRectangle = packer.PackRect(image.Width, image.Height, imageInfo);
                }
            }

            return(packer);
        }
示例#13
0
 private static Task <ImageResult> ToImageResult(byte[] bytes)
 {
     return(TaskV2.Run(() => {
         var stream = new MemoryStream(bytes);
         var image = ImageResult.FromStream(stream, ColorComponents.RedGreenBlueAlpha);
         stream.Dispose();
         Conversion.stbi__vertical_flip(image.Data, image.Width, image.Height, 4);
         return Task.FromResult(image);
     }));
 }
示例#14
0
        public async Task DownloadTest1()
        {
            var h      = 100;
            var w      = 50;
            var stream = await new Uri("https://picsum.photos/" + w + "/" + h).SendGET().GetResult <Stream>();
            var image  = ImageResult.FromStream(stream, ColorComponents.RedGreenBlueAlpha);

            stream.Dispose();
            Assert.Equal(h, image.Height);
            Assert.Equal(w, image.Width);
        }
示例#15
0
        public static async Task <ImageResult> LoadAndDispose(Stream stream)
        {
            stream = await stream.CopyToSeekableStreamIfNeeded(disposeOriginalStream : true);

            AssertV2.AreNotEqual(0, stream.Length, "LoadAndDispose: stream.Length");
            var image = ImageResult.FromStream(stream, ColorComponents.RedGreenBlueAlpha);

            stream.Dispose();
            Conversion.stbi__vertical_flip(image.Data, image.Width, image.Height, 4);
            return(image);
        }
示例#16
0
 public void LoadUnknownFormat(string filename)
 {
     Assert.Throws <InvalidOperationException>(() =>
     {
         ImageResult result = null;
         using (var stream = _assembly.OpenResourceStream(filename))
         {
             result = ImageResult.FromStream(stream, ColorComponents.RedGreenBlueAlpha);
         }
     });
 }
示例#17
0
        public unsafe static StaticSpriteFont FromBMFont(string data, Func <string, Stream> imageStreamOpener, ITexture2DManager textureManager)
#endif
        {
            var bmFont = LoadBMFont(data);

            var textures = new Dictionary <string, Texture2D>();

            for (var i = 0; i < bmFont.Pages.Length; ++i)
            {
                var    fileName = bmFont.Pages[i].FileName;
                Stream stream   = null;
                try
                {
                    stream = imageStreamOpener(fileName);
                    if (!stream.CanSeek)
                    {
                        // If stream isn't seekable, use MemoryStream instead
                        var ms = new MemoryStream();
                        stream.CopyTo(ms);
                        ms.Seek(0, SeekOrigin.Begin);
                        stream.Dispose();
                        stream = ms;
                    }

                    var image = ImageResult.FromStream(stream, ColorComponents.RedGreenBlueAlpha);
                    if (image.SourceComp == ColorComponents.Grey)
                    {
                        // If input image is single byte per pixel, then StbImageSharp will set alpha to 255 in the resulting 32-bit image
                        // Such behavior isn't acceptable for us
                        // So reset alpha to color value
                        for (var j = 0; j < image.Data.Length / 4; ++j)
                        {
                            image.Data[j * 4 + 3] = image.Data[j * 4];
                        }
                    }

#if MONOGAME || FNA || STRIDE
                    var texture = Texture2DManager.CreateTexture(device, image.Width, image.Height);
                    Texture2DManager.SetTextureData(texture, new Rectangle(0, 0, image.Width, image.Height), image.Data);
#else
                    var texture = textureManager.CreateTexture(image.Width, image.Height);
                    textureManager.SetTextureData(texture, new Rectangle(0, 0, image.Width, image.Height), image.Data);
#endif

                    textures[fileName] = texture;
                }
                finally
                {
                    stream.Dispose();
                }
            }

            return(FromBMFont(bmFont, fileName => new TextureWithOffset(textures[fileName])));
        }
示例#18
0
 public ImageTexture(string path)
 {
     try
     {
         using var stream = File.OpenRead(path);
         Image            = ImageResult.FromStream(stream, ColorComponents.RedGreenBlue);
     }
     catch (Exception e)
     {
         Console.WriteLine(e);
     }
 }
示例#19
0
        public async Task DownloadTest2()
        {
            var h     = 110;
            var w     = 60;
            var bytes = await new Uri("https://picsum.photos/" + w + "/" + h).SendGET().GetResult <byte[]>();

            using (var stream = new MemoryStream(bytes)) {
                var image = ImageResult.FromStream(stream, ColorComponents.RedGreenBlueAlpha);
                Assert.Equal(h, image.Height);
                Assert.Equal(w, image.Width);
            }
        }
示例#20
0
        private static ImageResult LoadImage(FileInfo imgFile)
        {
            if (!imgFile.ExistsV2())
            {
                throw Log.e("No image found at " + imgFile);
            }
            var stream = File.OpenRead(imgFile.FullName);
            var image  = ImageResult.FromStream(stream, ColorComponents.RedGreenBlueAlpha);

            stream.Dispose();
            return(image);
        }
示例#21
0
        public Texture(string image, GL gl)
        {
            _gl        = gl;
            _textureID = _gl.GenTexture();

            FileStream  stream = File.OpenRead("./Assets/Textures/" + image + ".png");
            ImageResult img    = ImageResult.FromStream(stream, ColorComponents.RedGreenBlueAlpha);

            _width  = (uint)img.Width;
            _height = (uint)img.Height;
            Load(img.Data);
        }
示例#22
0
        /// <summary>
        /// LoadContent will be called once per game and is the place to load
        /// all of your content.
        /// </summary>
        protected override void LoadContent()
        {
            // Create a new SpriteBatch, which can be used to draw textures.
            _spriteBatch = new SpriteBatch(GraphicsDevice);

            // Load image data into memory
            using (var stream = File.OpenRead(_filePath))
            {
                var image = ImageResult.FromStream(stream, ColorComponents.RedGreenBlueAlpha);
                _texture = new Texture2D(GraphicsDevice, image.Width, image.Height, false, SurfaceFormat.Color);
                _texture.SetData(image.Data);
            }
        }
示例#23
0
        public static ImageData Build(string id, string relative_path)
        {
            using var file = File.OpenRead(ResourceLoader.GetFullResourcePath(relative_path));

            var image = ImageResult.FromStream(file, ColorComponents.RedGreenBlueAlpha);

            var image_data = new ImageData()
            {
                Id     = id,
                Data   = image.Data,
                Width  = image.Width,
                Height = image.Height
            };

            return(image_data);
        }
示例#24
0
        public void Load(string filename, int width, int height, ColorComponents colorComponents)
        {
            ImageResult result = null;

            using (var stream = _assembly.OpenResourceStream(filename))
            {
                result = ImageResult.FromStream(stream, ColorComponents.RedGreenBlueAlpha);
            }

            Assert.IsNotNull(result);
            Assert.AreEqual(result.Width, width);
            Assert.AreEqual(result.Height, height);
            Assert.AreEqual(result.Comp, ColorComponents.RedGreenBlueAlpha);
            Assert.AreEqual(result.SourceComp, colorComponents);
            Assert.IsNotNull(result.Data);
            Assert.AreEqual(result.Data.Length, result.Width * result.Height * 4);
        }
示例#25
0
        public void Load(string filename, int width, int height, ColorComponents colorComponents, bool is16bit)
        {
            ImageResult result;

            using (var stream = _assembly.OpenResourceStream(filename))
            {
                result = ImageResult.FromStream(stream, ColorComponents.RedGreenBlueAlpha);
            }

            Assert.IsNotNull(result);

            Assert.AreEqual(result.Width, width);
            Assert.AreEqual(result.Height, height);
            Assert.AreEqual(result.SourceComponents, colorComponents);
            Assert.AreEqual(result.BitsPerChannel, is16bit ? 16 : 8);
            Assert.IsNotNull(result.Data);
            Assert.AreEqual(result.Data.Length, result.Width * result.Height * (int)result.ColorComponents);
        }
示例#26
0
        public Texture2DWrapper Load(AssetLoaderContext context, string assetName)
#endif
        {
            ImageResult result = null;

            using (var stream = context.Open(assetName))
            {
                if (stream.CanSeek)
                {
                    result = ImageResult.FromStream(stream, ColorComponents.RedGreenBlueAlpha);
                }
                else
                {
                    // If stream doesnt provide seek functionaly, use MemoryStream instead
                    using (var ms = new MemoryStream())
                    {
                        stream.CopyTo(ms);
                        ms.Seek(0, SeekOrigin.Begin);
                        result = ImageResult.FromStream(ms, ColorComponents.RedGreenBlueAlpha);
                    }
                }
            }

            // Premultiply Alpha
            var b = result.Data;

            for (var i = 0; i < result.Data.Length; i += 4)
            {
                var a = b[i + 3];
                b[i]     = ApplyAlpha(b[i], a);
                b[i + 1] = ApplyAlpha(b[i + 1], a);
                b[i + 2] = ApplyAlpha(b[i + 2], a);
            }

#if MONOGAME || FNA || STRIDE
            var texture = CrossEngineStuff.CreateTexture(MyraEnvironment.GraphicsDevice, result.Width, result.Height);
            CrossEngineStuff.SetTextureData(texture, new Rectangle(0, 0, result.Width, result.Height), result.Data);
            return(texture);
#else
            var texture = MyraEnvironment.Platform.CreateTexture(result.Width, result.Height);
            MyraEnvironment.Platform.SetTextureData(texture, new Rectangle(0, 0, result.Width, result.Height), result.Data);
            return(new Texture2DWrapper(result.Width, result.Height, texture));
#endif
        }
示例#27
0
        /// <summary>
        /// LoadContent will be called once per game and is the place to load
        /// all of your content.
        /// </summary>
        protected override void LoadContent()
        {
            // Create a new SpriteBatch, which can be used to draw textures.
            _spriteBatch = new SpriteBatch(GraphicsDevice);

            // Load image data into memory
            using (var stream = File.OpenRead(_filePath))
            {
                if (!_isAnimatedGif)
                {
                    var image   = ImageResult.FromStream(stream, ColorComponents.RedGreenBlueAlpha);
                    var texture = new Texture2D(GraphicsDevice, image.Width, image.Height, false, SurfaceFormat.Color);
                    texture.SetData(image.Data);

                    var frame = new FrameInfo
                    {
                        Texture   = texture,
                        DelayInMs = 0
                    };

                    _frames.Add(frame);
                }
                else
                {
                    _totalDelayInMs = 0;
                    foreach (var image in ImageResult.AnimatedGifFramesFromStream(stream))
                    {
                        var texture = new Texture2D(GraphicsDevice, image.Width, image.Height, false, SurfaceFormat.Color);
                        texture.SetData(image.Data);

                        var frame = new FrameInfo
                        {
                            Texture   = texture,
                            DelayInMs = image.DelayInMs
                        };

                        _totalDelayInMs += frame.DelayInMs;

                        _frames.Add(frame);
                    }
                }
            }
        }
示例#28
0
        /// <summary>
        /// LoadContent will be called once per game and is the place to load
        /// all of your content.
        /// </summary>
        protected override void LoadContent()
        {
            // Create a new SpriteBatch, which can be used to draw textures.
            _spriteBatch = new SpriteBatch(GraphicsDevice);

            // TODO: use this.Content to load your game content here

            // Load image data into memory
            var path = Path.GetDirectoryName(System.Reflection.Assembly.GetEntryAssembly().Location);

            path = Path.Combine(path, "image.jpg");

            using (var stream = File.OpenRead(path))
            {
                var image = ImageResult.FromStream(stream, ColorComponents.RedGreenBlueAlpha);
                _image = new Texture2D(GraphicsDevice, image.Width, image.Height, false, SurfaceFormat.Color);
                _image.SetData(image.Data);
            }

            GC.Collect();
        }
示例#29
0
        public static async Task <ImageInfo> GetImageInfoFrom(Stream source)
        {
            source = await source.CopyToSeekableStreamIfNeeded(disposeOriginalStream : true);

            try {
                try {
                    source.Seek(0, SeekOrigin.Begin);
                    return(ImageInfo.FromStream(source).Value);
                }
                catch (Exception e) { Log.w("ImageInfo.FromStream failed", e); }
                source.Seek(0, SeekOrigin.Begin);
                var img = ImageResult.FromStream(source);
                return(new ImageInfo()
                {
                    Width = img.Width, Height = img.Height
                });
            }
            catch (Exception e) { Log.w("ImageResult.FromStream failed", e); }
            source.Seek(0, SeekOrigin.Begin);
            // ExifLib.ExifReader closes the stream on error so has to be tried last
            return(GetInfoFromJpgExifReader(source));
        }
示例#30
0
        /// <summary>
        /// Creates image by loading it from the disk from specified file name.
        /// </summary>
        /// <returns>Handle to the image.</returns>
        public static int CreateImage(this Nvg nvg, string fileName, ImageFlags imageFlags)
        {
            Stream stream;

            try
            {
                stream = File.OpenRead(fileName);
            }
            catch
            {
                return(0);
            }
            ImageResult result = ImageResult.FromStream(stream, ColorComponents.RedGreenBlueAlpha);

            if (result == null)
            {
                return(0);
            }
            int image = CreateImageRgba(nvg, (uint)result.Width, (uint)result.Height, imageFlags, result.Data);

            stream.Close();
            stream.Dispose();
            return(image);
        }