Пример #1
0
 private Bitmap GetImage(string resourcePath)
 {
     if (this.image == null)
     {
         string str = this.pathName;
         if (!Path.IsPathRooted(this.pathName))
         {
             str = Path.Combine(resourcePath, this.pathName);
         }
         try
         {
             if (File.Exists(str))
             {
                 string lower  = Path.GetExtension(str).ToLower();
                 Pixbuf pixbuf = PixbufHelper.Load(str);
                 this.image = new Bitmap((Stream) new MemoryStream(pixbuf.SaveToBuffer(lower.Trim('.'))));
                 pixbuf.Dispose();
             }
         }
         catch (Exception ex)
         {
             MessageBox.Show("Ex : " + ex.Message, (Gtk.Window)null, (string)null, MessageBoxImage.Info);
             return((Bitmap)null);
         }
     }
     return(this.image);
 }
Пример #2
0
        public bool PackerWithList(List <string> fileNameList, string fullPath, string projectName, bool bClip, ImageFileFormat fileFormat, string resoucesPath, float resourceScale, bool bEachFile = false)
        {
            if (!Directory.Exists(fullPath))
            {
                Directory.CreateDirectory(fullPath);
            }
            this.fullPathStr    = fullPath;
            this.projectNameStr = projectName;
            this.saveFileFormat = fileFormat;
            this.bAllCheck      = bEachFile;
            switch (this.saveFileFormat)
            {
            case ImageFileFormat.Png:
                this.saveImageFormat = ImageFormat.Png;
                break;

            case ImageFileFormat.Jpeg:
                this.saveImageFormat = ImageFormat.Jpeg;
                break;
            }
            this.resourcePathStr      = resoucesPath;
            this.clipState            = bClip;
            this.perCountForFullImage = (float)((double)fileNameList.Count * 1.0 / 200.0);
            this.fResourceScale       = resourceScale;
            List <string> stringList = new List <string>();

            foreach (string fileName in fileNameList)
            {
                string extensions = this.GetExtensions(fileName);
                if (extensions == ".png" || extensions == ".jpg")
                {
                    string str = fileName;
                    if (!Path.IsPathRooted(fileName))
                    {
                        str = Path.Combine(this.resourcePathStr, fileName);
                    }
                    Bitmap _map = (Bitmap)null;
                    try
                    {
                        if (File.Exists(str))
                        {
                            Pixbuf pixbuf = PixbufHelper.Load(str);
                            _map = new Bitmap((Stream) new MemoryStream(pixbuf.SaveToBuffer(extensions.Trim('.'))));
                            pixbuf.Dispose();
                        }
                    }
                    catch (Exception ex)
                    {
                        MessageBox.Show("Ex : " + ex.Message, (Gtk.Window)null, (string)null, MessageBoxImage.Info);
                        break;
                    }
                    if (_map != null)
                    {
                        this.spriteList.Add(new PackerSprite(_map, fileName, this.clipState, true, resourceScale));
                        _map.Dispose();
                        this.RaiseProcessChange(this.perCountForFullImage);
                    }
                }
                else if (this.GetExtensions(fileName) == ".plist")
                {
                    stringList.Add(fileName);
                    this.CopyPlistAndBigImage(fileName, this.fullPathStr);
                    this.RaiseProcessChange(this.perCountForFullImage);
                }
            }
            foreach (string str in stringList)
            {
                fileNameList.Remove(str);
            }
            this.CalculationSpriteList(this.spriteList);
            this.SaveAllFile();
            return(this.bResult);
        }