Fixing bug, ApngDecoder can read again non png files.
This commit is contained in:
parent
f70045ac67
commit
323623b5fa
|
@ -15,7 +15,7 @@ class Loader {
|
|||
* @param url Url of the file to download.
|
||||
* @return [ByteArray] of the file.
|
||||
*/
|
||||
@Throws(IOException::class)
|
||||
@Throws(IOException::class, Exception::class)
|
||||
suspend fun load(url: URL): ByteArray =
|
||||
withContext(Dispatchers.IO) {
|
||||
val connection = url.openConnection() as HttpURLConnection
|
||||
|
|
|
@ -59,7 +59,7 @@ class ApngDecoder {
|
|||
fun decodeApng(context: Context, inStream: InputStream, speed: Float = 1f, config : Bitmap.Config = Bitmap.Config.ARGB_8888): Drawable {
|
||||
val inputStream = BufferedInputStream(inStream)
|
||||
val bytes = ByteArray(8)
|
||||
inputStream.mark(0)
|
||||
inputStream.mark(8)
|
||||
inputStream.read(bytes)
|
||||
if (isPng(bytes)) {
|
||||
var png: ArrayList<Byte>? = null
|
||||
|
@ -197,6 +197,8 @@ class ApngDecoder {
|
|||
BitmapDrawable(
|
||||
context.resources,
|
||||
if (btm.config != config) {
|
||||
if (BuildConfig.DEBUG)
|
||||
Log.v(TAG, "Bitmap Config : ${btm.config}, Config : $config")
|
||||
btm.copy(config, btm.isMutable)
|
||||
} else {
|
||||
btm
|
||||
|
@ -303,6 +305,8 @@ class ApngDecoder {
|
|||
BitmapDrawable(
|
||||
context.resources,
|
||||
if (btm.config != config) {
|
||||
if (BuildConfig.DEBUG)
|
||||
Log.v(TAG, "Bitmap Config : ${btm.config}, Config : $config")
|
||||
btm.copy(config, btm.isMutable)
|
||||
} else {
|
||||
btm
|
||||
|
|
|
@ -1,6 +1,7 @@
|
|||
package oupson.apngcreator.fragments
|
||||
|
||||
|
||||
import android.graphics.Bitmap
|
||||
import android.graphics.drawable.Drawable
|
||||
import android.os.Bundle
|
||||
import android.util.Log
|
||||
|
@ -36,6 +37,7 @@ class ApngDecoderFragment : Fragment() {
|
|||
this.context!!,
|
||||
URL("https://metagif.files.wordpress.com/2015/01/bugbuckbunny.png"),
|
||||
imageView,
|
||||
config = Bitmap.Config.RGB_565,
|
||||
callback = object : ApngDecoder.Callback {
|
||||
override fun onSuccess(drawable: Drawable) {
|
||||
if (BuildConfig.DEBUG)
|
||||
|
|
Loading…
Reference in New Issue