Пример #1
0
 /// <summary>
 /// Converts a common image file (<see cref="System.Drawing.Image"/> backend) into a WcgImage.
 /// </summary>
 /// <param name="file">Path to the image file.</param>
 /// <returns>WcgImage representation of the image.s</returns>
 public static WcgImage FromImage(string file)
 {
     using (var img = Image.FromFile(file))
     {
         return(WcgImage.FromImage(img));
     }
 }
Пример #2
0
        public void ReplaceImage(string path, WcgImage image, int?x = null, int?y = null)
        {
            //Width = Math.Max(image.Width, Width);
            //Height = Math.Max(image.Height, Height);
            path = Path.GetFileNameWithoutExtension(path);

            byte[] data;
            using (var memory = new MemoryStream())
            {
                image.Save(memory);
                data = memory.ToArray();
            }


            byte     flag  = 0;
            LwgEntry entry = null;

            if (HasEntry(path))
            {
                entry = GetEntry(path);
            }
            else
            {
                entry      = new LwgEntry();
                entry.Path = path;

                _Entries.Add(entry);
            }

            entry.Content = data;
            entry.X       = x ?? entry.X;
            entry.Y       = y ?? entry.Y;
        }
Пример #3
0
        private static void FillEntry(LwgEntry entry, string path, bool aggressive)
        {
            string[] fileEndings = new string[] { ".wcg", ".msk" };
            entry.Content = new byte[0];

            if (entry.Flag != (byte)LWGFlags.String)
            {
                string ePath = Path.Combine(path, entry.Path);
                if (aggressive && File.Exists(ePath + ".png"))
                {
                    var img = WcgImage.FromImage(ePath + ".png");
                    using (var memory = new MemoryStream())
                    {
                        img.Save(memory);
                        entry.Content = memory.ToArray();
                    }
                }
                else
                {
                    foreach (var ext in fileEndings)
                    {
                        if (File.Exists(ePath + ext))
                        {
                            entry.Content = File.ReadAllBytes(ePath + ext);
                        }
                    }
                }
            }
        }
Пример #4
0
 public WcgImage ToWCG()
 {
     using (var memoryStream = new MemoryStream(Content)) {
         return(WcgImage.FromStream(memoryStream));
     }
 }