Пример #1
0
        public void RemoveImagePal(int imageIndex)
        {
            if (imageIndex < 0 || imageIndex >= ImagesPal.Count)
            {
                return;
            }

            ImagesPal.RemoveAt(imageIndex);
        }
Пример #2
0
        public void AddImagePal(Bitmap image, int position)
        {
            var img = new SpriteImagePal {
                Width   = (ushort)image.Width,
                Height  = (ushort)image.Height,
                Image   = image.Clone() as Bitmap,
                Decoded = true
            };

            img.Size = (ushort)(img.Width * img.Height);
            img.Data = new byte[img.Size];

            // build data
            for (var x = 0; x < img.Width; x++)
            {
                for (var y = 0; y < img.Height; y++)
                {
                    var c = image.GetPixel(x, y);
                    var i = Palette.IndexOf(c);
                    if (i == -1)
                    {
                        continue; // @TODO: color not found?
                    }
                    img.Data[(x + (y * img.Width))] = (byte)i;
                }
            }

            if (position >= ImagesPal.Count)
            {
                ImagesPal.Add(img);
            }
            else
            {
                ImagesPal[position].Image = null; // force redraw
                ImagesPal.Insert(position, img);
            }
        }