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

4.0.1-non-native #19

Merged
merged 3 commits into from
Sep 15, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 24 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
[![](https://jitpack.io/v/jens-muenker/uCrop-n-Edit.svg)](https://jitpack.io/#jens-muenker/uCrop-n-Edit) [![](https://jitpack.io/v/jens-muenker/uCrop-n-Edit/month.svg)](https://jitpack.io/#jens-muenker/uCrop-n-Edit)
#### Non Native Version
#### Non-Native Version
# uCrop'n'Edit - Image Cropping and Editing Library for Android

This repository is a fork of <a href="https://github.com/krokyze/uCrop-n-Edit">uCrop'n'Edit</a>, which is in turn a fork of <a href="https://github.com/Yalantis/uCrop">uCrop</a>. I fixed some bugs, updated the dependencies and gradle, and converted much of the code to Kotlin. Furthermore, I added the option to use an ActivityResultLauncher instead of onActivityResult which is deprecated. In addition, in the changelogs you can see all other features I added.
Expand All @@ -21,6 +21,26 @@ This repository is a fork of <a href="https://github.com/krokyze/uCrop-n-Edit">u
* the UI colors (Toolbar, StatusBar, active widget state)
* and more...

# Native vs Non-Native Version

I have split this repository into two separate branches:
- **Native**: `master`, `develop`
- **Non-Native**: `master-non-native`, `develop-non-native`

### Reason for the Split

The main reason for this split was the need for **WebP** file format support. While it is possible to implement this in the native version using [ImageMagick](https://imagemagick.org) as an additional layer for file handling (as mentioned [here](https://cimg.eu/reference/structcimg__library_1_1CImg.html)), I currently don't have the time to do so.

If someone has the time and interest to implement this, I would greatly appreciate it. Feel free to submit a pull request!

### Key Differences Between the Versions

- **Native Version**:
- Supports only JPEG, PNG, BMP, and [a few more formats](http://www.cimg.eu/reference/io.html).

- **Non-Native Version**:
- Supports JPEG, PNG, BMP, **WebP**, and possibly other [Android-supported image formats](https://developer.android.com/media/platform/supported-formats#image-formats) (untested).

# Usage

1. Include the library as a local library project in your build.gradle:
Expand Down Expand Up @@ -85,6 +105,9 @@ If you have any ideas for uCrop'n'Edit, feel free to let me know. I will try my

# Changelog

**4.0.1-non-native**
- fixed a file size bug (https://github.com/Yalantis/uCrop/pull/926)

**4.0.0-non-native**
- replaced native libraries with Kotlin implementations
- added support for webp (and possibly other [Android-supported image formats](https://developer.android.com/media/platform/supported-formats#image-formats), but I have not tested it yet)
Expand Down
5 changes: 2 additions & 3 deletions ucrop/src/main/java/com/yalantis/ucrop/task/BitmapCropTask.kt
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@ import android.renderscript.Element
import android.renderscript.RenderScript
import android.renderscript.ScriptIntrinsicConvolve3x3
import android.util.Log
import androidx.annotation.NonNull
import androidx.exifinterface.media.ExifInterface
import com.yalantis.ucrop.callback.BitmapCropCallback
import com.yalantis.ucrop.model.CropParameters
Expand Down Expand Up @@ -247,14 +246,14 @@ class BitmapCropTask(
}
}

private suspend fun saveImage(@NonNull croppedBitmap: Bitmap) = withContext(Dispatchers.IO) {
private suspend fun saveImage(croppedBitmap: Bitmap) = withContext(Dispatchers.IO) {
val context = contextRef.get() ?: return@withContext

var outputStream: OutputStream? = null
var outStream: ByteArrayOutputStream? = null

try {
outputStream = context.contentResolver.openOutputStream(mImageOutputUri)
outputStream = context.contentResolver.openOutputStream(mImageOutputUri, "wt")
outStream = ByteArrayOutputStream().also {
croppedBitmap.compress(mCompressFormat, mCompressQuality, it)
outputStream?.write(it.toByteArray())
Expand Down