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

quality parameter is ignored in Bitmap.Save with .jpg #12493

Closed
lostmsu opened this issue Aug 9, 2023 · 8 comments · Fixed by #12507
Closed

quality parameter is ignored in Bitmap.Save with .jpg #12493

lostmsu opened this issue Aug 9, 2023 · 8 comments · Fixed by #12507
Labels
bug help-wanted A contribution from the community would be most welcome.

Comments

@lostmsu
Copy link

lostmsu commented Aug 9, 2023

Describe the bug
The parameter does not appear to have any effect and no warning is reported.

To Reproduce
Steps to reproduce the behavior:

  1. Create a new Bitmap (I used WriteableBitmap) of ~1920x1080
  2. Fill it with non-trivial data
  3. Call bitmap.Save("test.jpg", quality: 10) (I also tried 1)

Expected behavior
You get a low quality version of the bitmap weighting under 100KB

Actual behavior
You get a high quality file over 1MB in size.
It appears the resulting file is actually a PNG instead of JPEG.

Screenshots
N/A

Desktop (please complete the following information):

  • OS: Windows
  • Version 11.0.2
@lostmsu lostmsu added the bug label Aug 9, 2023
@maxkatz6
Copy link
Member

@maxkatz6 maxkatz6 added the help-wanted A contribution from the community would be most welcome. label Aug 10, 2023
@timunie
Copy link
Contributor

timunie commented Aug 10, 2023

@lostmsu as @maxkatz6 pointed out where the bug may be, are you willing to provide a PR for a fix? It would be very appreciated.

@TETYYS
Copy link

TETYYS commented Aug 10, 2023

It appears the resulting file is actually a PNG instead of JPEG.

To be clear, check for file extension is not present here, it is always saved as PNG https://github.com/AvaloniaUI/Avalonia/blob/1896e8ad68dc0fdb6c1055d36a97b926e0a32f17/src/Skia/Avalonia.Skia/Helpers/ImageSavingHelper.cs#L57C51-L57C51

@kekekeks
Copy link
Member

We kinda need to add some basic support for BitmapEncoder API

@lostmsu
Copy link
Author

lostmsu commented Aug 10, 2023

I started working on support for image formats at least for saving. PR should be out in an hour or so.

@dbriard
Copy link
Contributor

dbriard commented Nov 30, 2023

Hi, this issue is closed but the PR do not seem to allow to save as Jpeg.

That would be really really really convinient if we can Save an Avalonia as Jpeg in addition to PNG, really.

My typical use case: I am doing image manipulation using my own buffer, and then I need to display it, and to save it as Jpeg. So I have to:

  1. Convert my buffer to SKBitmap to Save it as Jpeg
  2. Convert again to Avalonia Bitmap to display it
    I could avoid one unnecessary convertion if Avalonia allow me to save as Jpeg directly.

@workgroupengineering
Copy link
Contributor

My typical use case: I am doing image manipulation using my own buffer, and then I need to display it, and to save it as Jpeg. So I have to:

1. Convert my buffer to SKBitmap to Save it as Jpeg

2. Convert again to Avalonia Bitmap to display it
   I could avoid one unnecessary convertion if Avalonia allow me to save as Jpeg directly.

You can use only SKBitmap. To display it, see this.

@dbriard
Copy link
Contributor

dbriard commented Nov 30, 2023

My typical use case: I am doing image manipulation using my own buffer, and then I need to display it, and to save it as Jpeg. So I have to:

1. Convert my buffer to SKBitmap to Save it as Jpeg

2. Convert again to Avalonia Bitmap to display it
   I could avoid one unnecessary convertion if Avalonia allow me to save as Jpeg directly.

You can use only SKBitmap. To display it, see this.

Correct, there is this workaround, thanks for the remainder.

I am also investigating to see if I can create a SKImage pointing to an existing memory buffer for the save operation.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug help-wanted A contribution from the community would be most welcome.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

7 participants