I am trying to create an animated sprite from a spritesheet in wpf. The current technique I am using is breaking down an image of containing all the frames of the animation into separate images and just swapping them out.
However this is costly on memory and was wondering if there is a way to just draw a section of an image (specify the source rectangle) rather than splitting the image up.
You can definitely do this. In order for this to be supported by WPF's built-in animation system you need to animate a dependency property . In your case it seems you want to animate the SourceRect
property of a CroppedBitmap
using a RectAnimationUsingKeyFrames
with the DiscreteRectKeyFrame
class.
If you're displaying the image using an Image
element then you would set it's Source
property to a CroppedBitmap
, then the cropped bitmap would have its Source
property set to a BitmapImage
. The cropped bitmap wraps the standard bitmap and adds cropping functionality.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.