Esempio n. 1
0
        public SpriteSheetResourceData LoadSpriteSheetImage(string imagePath, Bitmap image)
        {
            if (!(Image.IsAlphaPixelFormat(image.PixelFormat)))
            {
                ImageHelper.AdjustImagePixelFormat(ref image);

                if (Image.IsAlphaPixelFormat(image.PixelFormat))
                {
                    Messager.ShowMessage(Messager.Mode.Message, "Image converted to alpha pixel format");
                }
            }


            var spTex = new Texture(image);

            spTex.Options.Filter = Configuration.TextureFilterMode;

            var id = string.Format("{0}", _spriteSheetsImages.Count);


            var spriteSheetResourceData = new SpriteSheetResourceData(imagePath, id, spTex);

            _spriteSheetsImages.Add(id, spriteSheetResourceData);

            return(spriteSheetResourceData);
        }
Esempio n. 2
0
        private string GetImagePath(string initialDirectory)
        {
            MainWindow.OpenFileDlg.Title            = Resources.Import_SpriteSheet_Text;
            MainWindow.OpenFileDlg.RestoreDirectory = true;
            MainWindow.OpenFileDlg.InitialDirectory = initialDirectory.Length > 0
                                                          ? initialDirectory
                                                          : Environment.GetFolderPath(Environment.SpecialFolder.Desktop);

            MainWindow.OpenFileDlg.Multiselect = false;

            MainWindow.OpenFileDlg.Filter = "Image Files|";


            foreach (var ext in ImageHelper.AllowedImageExtensions)
            {
                MainWindow.OpenFileDlg.Filter += string.Format("*.{0};", ext);
            }


            if (MainWindow.OpenFileDlg.ShowDialog() == DialogResult.OK)
            {
                if (ImageHelper.CheckImage(MainWindow.OpenFileDlg.FileName))
                {
                    return(MainWindow.OpenFileDlg.FileName);
                }
                Size maxTexturesize = RenderDisplayManager.MaxTextureSize;
                Messager.ShowMessage(Messager.Mode.Exception,
                                     string.Format(
                                         "Error loading image. Image extension must be PNG, JPG, GIF or BMP and size must be lower than {0}x{1}  pixels!",
                                         maxTexturesize.Width, maxTexturesize.Height));
            }
            return(string.Empty);
        }
Esempio n. 3
0
        public void ClearColor(ColorU color)
        {
            Bitmap spriteSheetTexBitmap = Texture.Surface.ToBitmap();

            Color clearedColor = ImageHelper.ClearColor(ref spriteSheetTexBitmap, color.ToColor());

            TransparentColors.Add(new ColorU(clearedColor));

            ResetTextureFromBitmap(spriteSheetTexBitmap);

            spriteSheetTexBitmap.Dispose();
        }
Esempio n. 4
0
        public void ClearColor(int x, int y)
        {
            Bitmap spriteSheetTexBitmap = Texture.Surface.ToBitmap();

            Color clearedColor = ImageHelper.ClearColor(ref spriteSheetTexBitmap, x, y);

            ColorU clearedColorConverted = new ColorU(clearedColor);

            if (!TransparentColors.Contains(clearedColorConverted))
            {
                TransparentColors.Add(clearedColorConverted);
            }


            ResetTextureFromBitmap(spriteSheetTexBitmap);

            spriteSheetTexBitmap.Dispose();
        }
Esempio n. 5
0
        public SpriteSheetResourceData LoadSpriteSheetFromSeparateImages(Bitmap[] images)
        {
            BitmapAtlas imageAtlas = new BitmapAtlas();


            for (int i = 0; i < images.Length; i++)
            {
                var image = images[i];
                if (!(Image.IsAlphaPixelFormat(image.PixelFormat)))
                {
                    ImageHelper.AdjustImagePixelFormat(ref image);
                }
                imageAtlas.AddImage(i.ToString(), image);
            }

            var spTex = imageAtlas.ToTexture(PixelFormat.DefaultAlpha);


            var finalSpTex = SpriteSheetAndTextureFuncs.TrimmByAlpha(spTex);

            finalSpTex.Options.Filter = Configuration.TextureFilterMode;

            spTex.Dispose();


            var id = string.Format("{0}", _spriteSheetsImages.Count);

            var spName = string.Format("AssembledSpriteSheet{0}", id);

            var spriteSheetResource = new SpriteSheetResourceData(spName, id, finalSpTex);

            _spriteSheetsImages.Add(id, spriteSheetResource);

            imageAtlas.Dispose();

            return(spriteSheetResource);
        }