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

Android: When a photo is taken or uploaded using the capacitor camera plugin the resizing produces poor image quality with jagged lines #2292

Open
samiMotorC opened this issue Jan 9, 2025 · 0 comments

Comments

@samiMotorC
Copy link

samiMotorC commented Jan 9, 2025

Bug Report

Plugin(s)

[capacitor] @capacitor/[email protected]

Capacitor Version

   Capacitor Doctor   

Latest Dependencies:

  @capacitor/cli: 6.2.0
  @capacitor/core: 6.2.0
  @capacitor/android: 6.2.0
  @capacitor/ios: 6.2.0

Installed Dependencies:

  @capacitor/ios: not installed
  @capacitor/cli: 6.2.0
  @capacitor/android: 6.2.0
  @capacitor/core: 6.2.0

Platform(s)

Android

Current Behavior

When a photo is resized down using the built in capacitor camera plug in the output image seems to lose quality creating a very pixilated image with jagged edges. This occurs with both CameraSource.Photos and CameraSource.Camera.

Expected Behavior

The image size is reduced but image maintains its quality with smooth edges and way less pixelated

Code Reproduction

Clone the following Ionic app repo and build it onto an android device.

https://github.com/samiMotorC/RtsScanner

Open the app and use it to take a photo or to upload an image from your gallery.
View the output image and double tap to zoom in, better revealing the pixelation.

Other Technical Details

Additional Context

Tested on Samsung Galaxy S22 Ultra (Camera resolution 1868x4000px)

Images resized to 1024x1024px

I believe the issue is due to the following scaling algorithm used by the camera capacitor plugin:

return Bitmap.createBitmap(bitmap, 0, 0, bitmap.getWidth(), bitmap.getHeight(), matrix, true);

A similar issue is mentioned in this stackoverflow issue using createdScaledBitmap results in pixelated images. The top answer supplies an alternative means of scaling using Bitmap.createBitmap and Canvas.

Here is a comparison of the pixelated capacitor image:
capacitor image

Compared to an image taken using the same device and resized to the same size using JavaScript:
javascript image

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

No branches or pull requests

2 participants