Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Cropped image size is too small #1

Closed
DaveInCaz opened this issue Jul 13, 2018 · 2 comments
Closed

Cropped image size is too small #1

DaveInCaz opened this issue Jul 13, 2018 · 2 comments

Comments

@DaveInCaz
Copy link

Thanks for posting your code for this project.

Testing it out I noticed an issue where the saved image size would be somewhat too small. The resulting cropped image (saved to disk) appears to be cut off somewhat on the right / bottom at least.

The simplest test cases is:

  1. Run sample program
  2. Load any sample image
  3. Select the entire image as the crop area
  4. Save
  5. Resulting saved image is smaller than the original

I am running in 120 DPI, I'm not sure if that is related to this issue.

Many thanks

@ArXen42
Copy link
Contributor

ArXen42 commented Feb 4, 2020

This is quite old issue, but additional comment probably won't hurt :)

It seems I encountered the same issue. Cropped image is more or less correct when using usual 24'' FHD, but when using 4K laptop display, only small part of cropped area is actually saved. I guess something is off with that DPI trickery inside GetCroppedBitmapFrame:

Matrix m       = pSource.CompositionTarget.TransformToDevice;
double dpiX    = m.M11 * 96;
double dpiY    = m.M22 * 96;

// 2) create RenderTargetBitmap
var elementBitmap = new RenderTargetBitmap(
    (int) AdornedElement.RenderSize.Width,
    (int) AdornedElement.RenderSize.Height,
    dpiX,
    dpiY,
    PixelFormats.Default
);

I personally don't need that BitmapImage related functionality, but this is probably the place to look if someone else will need this to work.

My use case is a bit different (more MVVM style): crop adorner is rendered upon preview image and I only need to get info on it's relative position and size for later batch processing. PR with these changes is almost ready if anyone else will need this.

@dmitryshelamov
Copy link
Owner

I was able to reproduce this issue.

Look like the when you load image, window do not properly resize by default.
Setting SizeToContent ="WidthAndHeight" in CroppingWindow.xaml solve this issue

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

No branches or pull requests

3 participants