Reputation: 35
if (map[x, y] != null)
save.SetPixel(x, y, System.Drawing.Color.FromArgb(map[x, y].r, map[x, y].g, map[x, y].b));
This code is part of a function where x and y are ints. save is a Bitmap.
save = CreateNonIndexedImage(Bitmap.FromFile("Content/save/map.png"));
map[,] is an array consisting of Tile, which is a class of mine. Tile.r, Tile.g and Tile.b are ints.
Why is this throwing a ArgumentException?
The StackTrace:
bei System.Drawing.Image.get_Width()
bei System.Drawing.Bitmap.SetPixel(Int32 x, Int32 y, Color color)
bei RogueLike.Game1.saveTile(Int32 x, Int32 y) in C:\Users\Niklas\Documents\Visual Studio 2010\Projects\RogueLike\RogueLike\RogueLike\Game1.cs:Zeile 472.
Upvotes: 0
Views: 689
Reputation: 56716
According to MSDN, Bitmap.SetPixel
does not throw the ArgumentException, however Color.FromArgb
does when
red, green, or blue is less than 0 or greater than 255.
Therefore one of map[x, y].r
, map[x, y].g
or map[x, y].b
is outside of the integer interval [0..255]
.
Upvotes: 2
Reputation: 11273
My guess is that your image is smaller than your data, causing out of range exceptions in your SetPixel function call.
Upvotes: 0