C#C
C#2y ago
Tsjech

Bitmap PixelFormat causing OutOfMemoryException

When I add a size to Bitmap bmp setting the label.Image throws an OutOfMemoryException, but not when I remove the size to Bitmap bmp
Does anyone know what I have to do to fix this?
    private void PromotePiece(Move move)
    {
        Bitmap bmp = new Bitmap(PiecesImage, boxSize, boxSize);

        if (move.PromotedPiece is Knight) {
            Label promotionKnigt = new Label();
            promotionKnigt.Location = new Point(move.Location.X * boxSize + boxSize / 2, move.Location.Y * boxSize);
            promotionKnigt.Size = new Size(boxSize, boxSize);
            promotionKnigt.Image = bmp.Clone(move.PromotedPiece.PieceOfImage, bmp.PixelFormat);
            promotionKnigt.Click += PromoteToKnight;
            this.Controls.Add(promotionKnigt);
        } else {
            Label promotionQueen = new Label();
            promotionQueen.Location = new Point(move.Location.X * boxSize + boxSize / 2, (move.Location.Y + 1) * boxSize);
            promotionQueen.Size = new Size(boxSize, boxSize);
            promotionQueen.Image = bmp.Clone(move.PromotedPiece.PieceOfImage, bmp.PixelFormat);
            promotionQueen.Click += PromoteToQueen;
            this.Controls.Add(promotionQueen);
        }
    }
Was this page helpful?