Skip to content

Conversation

Yushu2606
Copy link

@Yushu2606 Yushu2606 commented Oct 11, 2025

Prerequisites

  • I have written a descriptive pull-request title
  • I have verified that there are no overlapping pull-requests open
  • I have verified that I am following the existing coding patterns and practice as demonstrated in the repository. These follow strict Stylecop rules 👮.
  • I have provided test coverage for my change (where applicable)

Description

This pull request enhances the DrawImage functionality by adding animation loop control through a new repeatCount parameter. This allows users to control how many times animated images (GIFs, APNGs, WebP animations, etc.) should loop when drawn onto another image.
Close #2997

Changes Made

  • Added repeatCount parameter to all DrawImage extension methods in DrawImageExtensions.cs
  • Updated DrawImageProcessor constructors to accept and store the repeatCount parameter
  • Enhanced DrawImageProcessor<TPixelBg, TPixelFg> with animation frame cycling logic:
    • Added currentFrameLoop field to track animation progress
    • Implemented frame selection based on current loop count
    • Added validation to ensure repeatCount >= 0
    • Added loop termination logic (0 = infinite, >0 = specific count)

Key Features

  • Animation Control: repeatCount parameter controls how many times an animated image loops
    • 0 = infinite loop
    • >0 = specific number of loops
  • Frame Cycling: Automatically cycles through animation frames based on loop count
  • Backward Compatibility: All existing DrawImage method signatures are preserved with the new parameter added

Usage Example

// Draw animated GIF with infinite loop
image.DrawImage(animatedGif, opacity: 0.8f, repeatCount: 0);

// Draw animated GIF with 3 loops
image.DrawImage(animatedGif, opacity: 0.8f, repeatCount: 3);

// Draw at specific location with animation control
image.DrawImage(animatedGif, new Point(10, 10), opacity: 0.8f, repeatCount: 2);

Technical Details

  • The implementation tracks the current frame loop using currentFrameLoop field
  • Frame selection uses modulo operation: currentFrameIndex = currentFrameLoop % ForegroundImage.Frames.Count
  • Loop termination is handled by checking if current loop count exceeds the specified repeatCount
  • Validation ensures repeatCount is non-negative using Guard.MustBeGreaterThanOrEqualTo

Images

before after (loop count is 0)
Image Image

…nimation control in DrawImageExtensions and DrawImageProcessor classes.
@CLAassistant
Copy link

CLAassistant commented Oct 11, 2025

CLA assistant check
All committers have signed the CLA.

@CLAassistant
Copy link

CLA assistant check
Thank you for your submission! We really appreciate it. Like many open source projects, we ask that you sign our Contributor License Agreement before we can accept your contribution.
You have signed the CLA already but the status is still pending? Let us recheck it.

@JimBobSquarePants
Copy link
Member

HI @Yushu2606

It's standard practice to create a post here in our Ideas channel for feature enhancements to ensure that any new features are fully fleshed out before discussion. Upon reading this PR I'm not sure exactly what benefit this feature actually brings.

Could you please visit the channel and state you case. Thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants