Пример #1
0
        public RCode LoadFromFile(string sImageFile, ResourcePack pack)
        {
            Bitmap bmp;

            try
            {
                if (pack != null)
                {
                    // Load sprite from input stream
                    ResourceBuffer rb        = pack.GetFileBuffer(sImageFile);
                    var            imageData = rb.Memory.ToArray();
                    bmp = new Bitmap(new MemoryStream(imageData));
                }
                else
                {
                    // Load sprite from file
                    bmp = new Bitmap(sImageFile);
                }
            }
            catch (Exception ex)
            {
                Log.Warn($"Unable to load image {sImageFile}", ex);
                return(RCode.NO_FILE);
            }

            Width     = (uint)bmp.Width;
            Height    = (uint)bmp.Height;
            ColorData = new Pixel[Width * Height];
            for (int x = 0; x < Width; x++)
            {
                for (int y = 0; y < Height; y++)
                {
                    Color p = bmp.GetPixel(x, y);
                    SetPixel((uint)x, (uint)y, new Pixel(p.R, p.G, p.B, p.A));
                }
            }

            bmp.Dispose();

            return(RCode.OK);
        }
Пример #2
0
        public RCode LoadFromPGESprFile(string sImageFile, ResourcePack pack)
        {
            DataReader ReadData = (br) =>
            {
                Width     = (uint)br.ReadInt32();
                Height    = (uint)br.ReadInt32();
                ColorData = new Pixel[Width * Height];
                for (int i = 0; i < (Width * Height); i++)
                {
                    ColorData[i] = br.ReadUInt32();
                }
            };

            try
            {
                if (pack == null)
                {
                    using (BinaryReader br = new BinaryReader(File.OpenRead(sImageFile)))
                    {
                        ReadData(br);
                        return(RCode.OK);
                    }
                }
                else
                {
                    ResourceBuffer rb = pack.GetFileBuffer(sImageFile);
                    using (BinaryReader br = new BinaryReader(new MemoryStream(rb.Memory.ToArray())))
                    {
                        ReadData(br);
                    }
                    return(RCode.OK);
                }
            }
            catch (Exception)
            {
                return(RCode.FAIL);
            }
        }