Fix Multiple Bugs in Crop Functionality#284
Merged
Ruben2776 merged 2 commits intoRuben2776:devfrom Dec 9, 2025
Merged
Conversation
Ruben2776
approved these changes
Dec 9, 2025
Owner
|
Thank you very much, it looks great!
Currently, only manual testing has been set up. I'm gradually working on moving code-behind into MVVM to make the code cleaner and more maintainable, which should also theoretically allow the project to be testable. Any help from anyone would be greatly appreciated. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Description
While using PicView's "Crop" feature, I encountered several bugs and have attempted to fix them in this PR. Here is a brief introduction to the issues:
1. TextBlock Overlap at Top Edge:
When the crop area is close to the top edge of the window, the TextBlock displaying the crop dimensions is partially covered, making the values hard to read.
2. TextBlock Overlap at Right Edge:
When the crop area is close to the right side of the image, the TextBlock is also partially covered, making it impossible to view the values.
3. Incorrect Initial Crop Size for Small Images:
For images with small dimensions, the initial crop area size is incorrect. For example, after clicking the crop button, the initial width may be 537, while the image itself is only 300 pixels wide. At the same time, in the incorrect case, the crop area’s left and right borders are not visible, as they are clipped outside the image bounds.
Comparing the two pictures above and below, it is clear that the left and right boundaries of the cropped area in the top picture (the white line) are not visible.
4. Crop Area Size is (0, 0) for Certain Resolutions:
For images within a specific resolution range, the default crop area size is set to (0, 0).
Bug Analysis and Fixes:
1. Top Edge Overlap:
The calculation for the TextBlock position only handled the case when
topLeftY == 0, ignoring the thickness of the TextBlock itself.Original code:
Fix:
Update to:
This ensures the TextBlock is always visible.

2. Right Edge Overlap:
For large images, you can calculate the TextBlock width and adjust its left position using SetLeft. However, for very small images, the TextBlock will inevitably be clipped. Therefore, I suggest changing the parent container’s ClipToBounds property to False:
3 & 4. Incorrect Initial Crop Size:
These bugs are due to incomplete logic in CropLayoutManager initialization.
Original code:
Problems:
When DefaultSelectionSize < pixelWidth < DefaultSelectionSize * 2, there is no logic, resulting in crop area width/height being zero.
Since the current DefaultSelectionSize is set to 200, if an image has a resolution between 200 and 400 (for example, 350 × 350), this will trigger the bug where the initial crop area size is zero.
The crop size should be based on ImageWidth, not pixelWidth. For example, if pixelWidth = 300 but the displayed ImageWidth is only 118 due to scaling, the initial crop width should not exceed 118 / 2.
Fix:
How Has This Been Tested?
Maybe this can only be tested manually?
Types of changes
Checklist: