Yalantis / uCrop

Image Cropping Library for Android
https://yalantis.com/blog/introducing-ucrop-our-own-image-cropping-library-for-android/
11.85k stars 2.15k forks source link

CImg<unsigned char>::load(): Failed to recognize format of file '/data/user/0/com.yalantis.ucrop.sample/cache/SampleCropImage.jpg' #850

Closed youlookwhat closed 2 years ago

youlookwhat commented 2 years ago

Do you want to request a feature or report a bug? report a bug

What is the current behavior? 1、Just select input 1703 to 1000 2、Click PICK & CROP,It's the picture below crop20220815-162922 3、This is the configuration origin_img_v2_44647e8d-e23f-405a-b070-4aab532663bg

What is the expected behavior? It's not rotated,Can be cut.

If the current behavior is a bug, please provide the steps to reproduce and if possible a minimal demo of the problem. 1、Just select input 1703 to 1000 2、Select the image above

Please attach any image files, URL and stack trace that can be used to reproduce the bug. 1、image is crop20220815-162922

2、error log

2022-08-15 16:24:24.869 12312-12312/com.yalantis.ucrop.sample E/SampleActivity: handleCropError: 
    java.io.IOException: [instance(0,0,0,0,0x0,non-shared)] CImg<unsigned char>::load(): Failed to recognize format of file '/data/user/0/com.yalantis.ucrop.sample/cache/SampleCropImage.jpg'.
        at com.yalantis.ucrop.task.BitmapCropTask.cropCImg(Native Method)
        at com.yalantis.ucrop.task.BitmapCropTask.crop(BitmapCropTask.java:143)
        at com.yalantis.ucrop.task.BitmapCropTask.doInBackground(BitmapCropTask.java:92)
        at com.yalantis.ucrop.task.BitmapCropTask.doInBackground(BitmapCropTask.java:31)
        at android.os.AsyncTask$3.call(AsyncTask.java:389)
        at java.util.concurrent.FutureTask.run(FutureTask.java:266)
        at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1167)
        at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:641)
        at java.lang.Thread.run(Thread.java:929)

Which versions of uCrop, and which Android API versions are affected by this issue? Did this work in previous versions of uCrop? 1、version is 2.2.8,Download the code branch image 2、Previous versions also had this problem

youlookwhat commented 2 years ago

找到问题了,是一个 .webp格式的图片被修改图片后缀名为 .jpg了。然后这个库是不支持webp格式图片裁剪的。

可以将webp格式的图片复制成另一个jpg格式的图片,然后再进行裁剪的,亲测可行

IdioticMadman commented 1 year ago

看了一下,最新版本的cimg是支持了heif格式的

youlookwhat commented 1 year ago

我的是 后缀名是 .jpg,但是实质上是 heif 格式。然后用这个项目测不行。可能是后缀名没匹配上吧

IdioticMadman commented 1 year ago

ucrop的native代码没有用最新的cImg的库的代码的。 比较头疼,不知道怎么引入ndk里面的libheif库。不然是要自己编译libheif的库来用了吧

youlookwhat commented 1 year ago

难怪了,我们是直接将heif的图单独处理了

Hbottle commented 1 year ago

同样是遇到了这个问题,同一个目录下的图片,有的正常裁剪,有的报了上面的问题,但是我把文件从共享目录拷贝到app私有的目录,并修改文件名后就解决这个问题了。所以,到底是什么原因呢?

youlookwhat commented 1 year ago

同样是遇到了这个问题,同一个目录下的图片,有的正常裁剪,有的报了上面的问题,但是我把文件从共享目录拷贝到app私有的目录,并修改文件名后就解决这个问题了。所以,到底是什么原因呢?

有可能是上述原因,就是本质上图片还是heif 格式,只是强制将图片后缀名更改了。也可能是其他的原因了

Hbottle commented 1 year ago

我没有改后缀名,仅仅是将文件拷贝到app到cache目录,然后拿私有目录的这个文件去裁剪,所以具体啥原因我也不是很清楚,可能是权限的原因?

youlookwhat commented 1 year ago

照理说拷贝到app到cache目录再裁剪没问题的