コード例 #1
0
ファイル: Chunk.cs プロジェクト: djlw78/crayon
        public void GenerateTiles()
        {
            if (this.IsJPEG)
            {
                return;
            }

            if (this.Width != 1024 || this.Height != 1024)
            {
                return;
            }

            Tile[]            tiles    = new Tile[16];
            Bitmap.Graphics[] graphics = new Bitmap.Graphics[16];
            foreach (Image member in this.Members)
            {
                int startX     = member.ChunkX;
                int startY     = member.ChunkY;
                int endX       = startX + member.Width;
                int endY       = startY + member.Height;
                int tileStartX = startX / 256;
                int tileStartY = startY / 256;
                int tileEndX   = (endX - 1) / 256;
                int tileEndY   = (endY - 1) / 256;

                for (int tileY = tileStartY; tileY <= tileEndY; ++tileY)
                {
                    for (int tileX = tileStartX; tileX <= tileEndX; ++tileX)
                    {
                        int             tileIndex = tileX + tileY * 4;
                        Bitmap.Graphics tile      = graphics[tileIndex];
                        if (tile == null)
                        {
                            tiles[tileIndex] = new Tile()
                            {
                                Bitmap = new Bitmap(256, 256),
                                ChunkX = 256 * tileX,
                                ChunkY = 256 * tileY,
                                Width  = 256,
                                Height = 256,
                            };
                            tile = tiles[tileIndex].Bitmap.MakeGraphics();
                            graphics[tileIndex] = tile;
                        }

                        tile.Blit(member.Bitmap, member.ChunkX - tileX * 256, member.ChunkY - tileY * 256);
                    }
                }

                this.Tiles = new List <Tile>(tiles.Where(t => t != null));
            }

            foreach (Bitmap.Graphics graphicsInstance in graphics)
            {
                if (graphicsInstance != null)
                {
                    graphicsInstance.Cleanup();
                }
            }
        }
コード例 #2
0
 public IconSetGenerator AddInputImage(Bitmap bmp)
 {
     if (bmp.Width != bmp.Height)
     {
         int    size   = Math.Max(bmp.Width, bmp.Height);
         Bitmap newBmp = new Bitmap(size, size);
         this.ownedBitmapReferences.Add(newBmp);
         Bitmap.Graphics g = newBmp.MakeGraphics();
         int             x = (size - bmp.Width) / 2;
         int             y = (size - bmp.Height) / 2;
         g.Blit(bmp, x, y);
         bmp = newBmp;
     }
     this.bitmaps.Add(bmp);
     this.bitmapMaxDimenion.Add(Math.Max(bmp.Width, bmp.Height));
     return(this);
 }
コード例 #3
0
ファイル: IconSetGenerator.cs プロジェクト: djlw78/crayon
        public Dictionary <int, Bitmap> Generate()
        {
            Dictionary <int, Bitmap> lookup = new Dictionary <int, Bitmap>();

            Bitmap[] sources = this.bitmaps.OrderBy(b => - b.Width).ToArray();

            foreach (int desiredSize in this.outputSizes)
            {
                Bitmap          source = this.FindBestMatch(sources, desiredSize);
                Bitmap          bmp    = new Bitmap(desiredSize, desiredSize);
                Bitmap.Graphics g      = bmp.MakeGraphics();
                g.Blit(source, 0, 0, desiredSize, desiredSize);
                g.Cleanup();
                lookup.Add(desiredSize, bmp);
            }

            this.Cleanup();

            return(lookup);
        }