Esempio n. 1
0
        private void EditColorWheelItem(ColorWheelItem colorWheelItem, bool f)
        {
            if (colorWheelItem.CustomOccurency == 0f)
            {
                colorWheelItem.CustomOccurency = colorWheelItem.OriginalOccurency;
            }
            else
            {
                colorWheelItem.CustomOccurency = 0;
            }

            var usedPercentage = _colorWheelCollection.Sum(cwi => cwi.CustomOccurency);
            var factor         = 100f / usedPercentage;

            foreach (var item in _colorWheelCollection)
            {
                item.CustomOccurency *= factor;
            }

            if (!f)
            {
                UpdateGrid();
            }
        }
Esempio n. 2
0
        private void UpdateSprite()
        {
            if (ofdImage.ShowDialog(this) != DialogResult.OK)
            {
                return;
            }
            _spriteImage   = new Bitmap(ofdImage.FileName);
            btnSprite.Text = ofdImage.SafeFileName;

            var colorDictionary = new Dictionary <Color, int>();

            var total = 0;

            for (int x = 0; x < _spriteImage.Width; x++)
            {
                for (int y = 0; y < _spriteImage.Height; y++)
                {
                    var color = _spriteImage.GetPixel(x, y);
                    if (color.A != 255)
                    {
                        continue;
                    }
                    else
                    {
                        total++;
                    }

                    if (!colorDictionary.ContainsKey(color))
                    {
                        colorDictionary.Add(color, 1);
                    }
                    else
                    {
                        colorDictionary[color]++;
                    }
                }
            }

            var colorWheelCollection = new List <ColorWheelItem>();

            foreach (var pair in colorDictionary)
            {
                var occurency      = (pair.Value / (float)total) * 100f;
                var colorWheelItem = new ColorWheelItem(pair.Key, occurency);
                colorWheelCollection.Add(colorWheelItem);
            }

            _colorWheelCollection = colorWheelCollection;
            UpdateGrid();

            var spriteScaleValue = (int)(Math.Min(_exportImage.Width, _exportImage.Height) / Math.Min(_spriteImage.Width, _spriteImage.Height) * 10f);

            if (spriteScaleValue == 0)
            {
                spriteScaleValue = 1;
            }
            tkbSpriteScale.Value = spriteScaleValue;
            DrawBitmap();

            foreach (var colorWheelItem in _colorWheelCollection)
            {
                if (colorWheelItem.OriginalOccurency < 0.5f)
                {
                    EditColorWheelItem(colorWheelItem, true);
                }
            }
        }