The Fill method sets the entire ImageData to be the same color. For example, to make the entire ImageData black, use the following call:
Keep in mind that filling an ImageData is much slower than rendering to a texture. If you are working with large ImageDatas, avoid calling Fill on them frequently for performance reasons.
The ImageData class represents modifiable data that can be created from a Texture2D, or be used to construct a Texture2D. The ImageData class can be used to easily interact with the Texture2D class, and also provides a cross-platform way of creating and modifying textures.
Add the following using statements:
Add the following to Initialize after initializing FlatRedBall:
Note: This code uses the Color and Texture2D classes. Remember, if you are using a version of FlatRedBall other than FlatRedBall XNA, your using statements will be different. For more information, see:
Did this article leave any questions unanswered? Post any question in our forums for a rapid response.
FromTexture2D creates an ImageData object, filled with data from a Texture2D instance. It's important to note that the ImageData is a copy of the Texture2D, so making changes to the ImageData will not change the source Texture2D.
The following code shows how to create an ImageData instance from a Texture2D instance, then loop through each pixel:
ApplyColorOperation is a method which can be used to modify an ImageData using the same ColorOperation and Red,Green,Blue values that are present in the interface which is implemented by common FlatRedball objects such as and . ApplyColorOperation modifies the data stored in an ImageData permanently - it cannot be undone.
ApplyColorOperation can be used to modify a texture so that when rendered normally, it will appear the same as a Sprite with the same ColorOperation and Red/Green/Blue values. The following code shows a texture being rendered using a Modulate color operation: