Reputation: 11090
I have a bitmap that I have created by tiling the same graphic multiple times. When the bitmap is created it colours the tiles based on specific criteria.
When the bitmap is loaded, I then want to give the user the options to change the tile colours based on further pre-defined criteria. Would I therefore need to discard the current bitmap, generate again with the new colours and attach to the panel. Or can I iterate through the bitmap for each tile and change the colours that way?
Thanks.
Upvotes: 1
Views: 538
Reputation: 450
It depends on how often the user is likely to change the tile colours. If they're not going to be doing it too often then it's probably easier to generate a new bitmap (mostly because your code seems like it's optimized for this scenario).
A better more performant possibiliy however is to use the Bitmap.LockBits/UnlockBits methods to get at the pixel data in the bitmap then manipulate the pixel data direcly. See the MSDN documentation on the Bitmap.LockBits method (http://msdn.microsoft.com/en-us/library/5ey6h79d.aspx) for a sample on how to do this.
Upvotes: 1
Reputation: 60694
As far as I know, the only way you can go through the bitmap and change colors is to do it pixel by pixel, so I think your best shot is to generate the bitmap from scratch when the user selects new colors.
Upvotes: 1