mirror of
https://github.com/mihonapp/mihon.git
synced 2025-11-12 12:08:56 +01:00
Add an option to reencode images under the advanced tab. #262
This commit is contained in:
@@ -1,5 +1,7 @@
|
||||
package eu.kanade.tachiyomi.util
|
||||
|
||||
import android.graphics.Bitmap
|
||||
import android.graphics.BitmapFactory
|
||||
import okio.BufferedSource
|
||||
import okio.Okio
|
||||
import java.io.File
|
||||
@@ -36,4 +38,25 @@ fun BufferedSource.saveTo(stream: OutputStream) {
|
||||
it.flush()
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Saves the given source to an output stream and closes both resources.
|
||||
* The source is expected to be an image, and it may reencode the image.
|
||||
*
|
||||
* @param stream the stream where the source is copied.
|
||||
* @param reencode whether to reencode the image or not.
|
||||
*/
|
||||
fun BufferedSource.saveImageTo(stream: OutputStream, reencode: Boolean = false) {
|
||||
if (reencode) {
|
||||
use {
|
||||
val bitmap = BitmapFactory.decodeStream(it.inputStream())
|
||||
stream.use {
|
||||
bitmap.compress(Bitmap.CompressFormat.JPEG, 100, it)
|
||||
}
|
||||
bitmap.recycle()
|
||||
}
|
||||
} else {
|
||||
saveTo(stream)
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user