Search code examples
androidcsswebrtcimage-capture

object-fit:cover Not Working with ImageCapture.takePhoto on Mobile


I try to show the photo with object-fit:cover taken by the ImageCapture API. It works perfectly with Chrome on desktop. However, the object-fit:cover style is NOT working with Chrome on Android for ALL devices and emulators.

A minimal sample for this issue can be found here.

The size of <img id="photoImg" /> is fixed to 200 * 400 px to demonstrate the object-fit:cover style. The src of the image is generated from the ImageCapture.takePhoto() method and converted the blob to URL via URL.createObjectURL() function.

The following the result from Chrome on desktop, which is working perfectly.

Sadly, the following result from Chrome on Android (Sony Xperia 1) has the distorted image ratio. It seems the object-fit:cover does not work.

I have used Remote Debugging Android Devices to confirm that other object-fit values, such as object-fit:contain do work as expected.

I suspect that the Blob from ImageCapture might miss some critical pieces of information for the image ratio to be correctly calculated but I do not know how to investigate further.

How can I make the object-fit:cover work on mobile devices with Chrome?


Solution

  • After investigation, I find the root cause: a Chromium bug. It has been fixed and released in version 89. Thus, this question is no longer valid.