예제 #1
0
        /// <summary>
        /// Loads the given GBA.Palette onto the control.
        /// </summary>
        public void Load(IDisplayable image)
        {
            if (image == null)
            {
                Display = null;
                this.Invalidate();
                return;
            }
            if (image.Width % TileSize != 0)
            {
                throw new Exception("Image width is not a multiple of " + TileSize);
            }
            if (image.Height % TileSize != 0)
            {
                throw new Exception("Image height is not a multiple of " + TileSize);
            }

            Width   = image.Width;
            Height  = image.Height;
            Display = new Bitmap(Width, Height);
            for (int y = 0; y < Height; y++)
            {
                for (int x = 0; x < Width; x++)
                {
                    Display.SetPixel(x, y, (System.Drawing.Color)image.GetColor(x, y));
                }
            }

            Hovered = new Point();
            Hover   = null;

            this.Invalidate();
        }
예제 #2
0
        /// <summary>
        /// Creates a GBA.Bitmap from the given IDisplayable object
        /// </summary>
        public Bitmap(IDisplayable pixels)
        {
            Load(pixels.Width, pixels.Height);

            int index = 0;
            int pixel;
            Color color;
            for (int y = 0; y < Height; y++)
            for (int x = 0; x < Width; x++)
            {
                color = pixels.GetColor(x, y);
                pixel = Colors.Find(color);
                if (pixel == -1)
                {
                    pixel = Colors.Count;
                    Colors.Add(color);
                }
                Bytes[index++] = (byte)pixel;
            }
        }