TileToImage() public static method

public static TileToImage ( IList data, Color palette = null, int flags ) : Bitmap
data IList
palette Color
flags int
return System.Drawing.Bitmap
Example #1
0
        void draw(int tile)
        {
            int offset = tile * 16;

            if (!(offset >= offsetStart && offset < offsetEnd))
            {
                return;
            }

            int x = ((offset - offsetStart) / 16) % Width;
            int y = ((offset - offsetStart) / 16) / Width;

            int bank = 0;

            if (offset >= 0x1800)
            {
                offset -= 0x1800;
                bank    = 1;
            }
            byte[] data = new byte[16];
            Array.Copy(graphicsState.VramBuffer[bank], offset, data, 0, 16);
            Bitmap   subImage = GbGraphics.TileToImage(data);
            Graphics g        = Graphics.FromImage(image);

            g.DrawImage(subImage, x * 8, y * 8);

            QueueDraw();
        }
Example #2
0
        public Bitmap GetTileImage(int index)
        {
            if (tileImagesCache[index] != null)
            {
                return(tileImagesCache[index]);
            }

            Bitmap image = new Bitmap(16, 16);

            Graphics g = Graphics.FromImage(image);

            for (int y = 0; y < 2; y++)
            {
                for (int x = 0; x < 2; x++)
                {
                    int tileIndex = GetSubTileIndex(index, x, y);
                    int flags     = GetSubTileFlags(index, x, y);

                    int tileOffset = 0x1000 + ((sbyte)tileIndex) * 16;

                    byte[] src = new byte[16];
                    Array.Copy(graphicsState.VramBuffer[1], tileOffset, src, 0, 16);
                    Bitmap subImage = GbGraphics.TileToImage(src, GraphicsState.GetBackgroundPalettes()[flags & 7], flags);

                    g.DrawImageUnscaled(subImage, x * 8, y * 8);
                }
            }
            g.Dispose();

//             if (fullCachedImageData == null)
//                 fullCachedImageData = fullCachedImage.LockBits(
//                         new Rectangle(0, 0, fullCachedImage.Width, fullCachedImage.Height),
//                         ImageLockMode.ReadWrite, PixelFormat.Format24bppRgb);
//             GbGraphics.QuickDraw(fullCachedImageData, image, (index%16)*16, (index/16)*16);
            g = Graphics.FromImage(fullCachedImage);
            g.DrawImageUnscaled(image, (index % 16) * 16, (index / 16) * 16);
            g.Dispose();

            tileImagesCache[index] = image;
            return(image);
        }