Yalantis / uCrop

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

Support for Transparent images #622

Open sur950 opened 4 years ago

sur950 commented 4 years ago

Hi,

My image is transparent black logo and crop tool is adding black colour as default in background and after cropping, I see complete black screen and I would be very happy if you can add support for transparent images.

Thank you.

yenderlobo10 commented 4 years ago

May be you is not calling

UCrop.Options configInstance = new UCrop.Options();
configInstance.setCompressionFormat(Bitmap.CompressFormat.PNG)

... before start UCropActivity. You can do this building a UCrop.Options instances and pass it on

UCrop.of(from, cropTo).withOptions(configInstance);
sur950 commented 4 years ago

I will try that and will let you know.

gurpreet433 commented 4 years ago

yenderlobo10, the code you suggested is working perfectly, thank you. I tried it on real device moto E-4-plus Android KitKat. :)

gurpreet433 commented 4 years ago

yenderlobo10 but I don't know where it is documented though?

gurpreet433 commented 4 years ago

One more thing, it is working fine but if I have a completely black transparent png file then due to the background of the same colour it is not visible, so maybe that is the issue.

yenderlobo10 commented 4 years ago

yenderlobo10 but I don't know where it is documented though? imagen ... Maybe the documentation it's not specific enough. I had to snoop around in the source code of the library and the examples, to find out why it didn't work.

yenderlobo10 commented 4 years ago

One more thing, it is working fine but if I have a completely black transparent png file then due to the background of the same colour it is not visible, so maybe that is the issue.

I tested it on rooted Huawei P8 Lite, it worked with all the PNG's including your example. I advise you to check the examples in the library.

sur950 commented 4 years ago

One more thing, it is working fine but if I have a completely black transparent png file then due to the background of the same colour it is not visible, so maybe that is the issue.

This is what the exact problem is and the issue is also pointed to the same. I tried Mi5, OnePlus5 with a black transparent image but as the background of the activity area is also black it is hard to find where exactly the image is and what we are cropping.

If you can make it distinguishable that will be really a cool thing to use. (For white transparent images it works fine as the activity background is black but the issue is only for black transparent images).

Thank you.