Bitmap PixelFormat causing OutOfMemoryException
When I add a size to Bitmap
Does anyone know what I have to do to fix this?
bmpbmp setting the label.Imagelabel.Image throws an OutOfMemoryExceptionOutOfMemoryException, but not when I remove the size to Bitmap bmpbmpDoes 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);
}
} 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);
}
}