From 6c2dc3ca636dc3d09a9fc8bdb44565af65988409 Mon Sep 17 00:00:00 2001 From: tibbi Date: Sun, 9 Apr 2017 13:03:56 +0200 Subject: [PATCH] center the selected bitmap at drawing --- .../com/simplemobiletools/draw/MyCanvas.kt | 24 +++++++++++++++---- .../draw/activities/MainActivity.kt | 2 +- 2 files changed, 21 insertions(+), 5 deletions(-) diff --git a/app/src/main/kotlin/com/simplemobiletools/draw/MyCanvas.kt b/app/src/main/kotlin/com/simplemobiletools/draw/MyCanvas.kt index e1c81c3..c2269dc 100644 --- a/app/src/main/kotlin/com/simplemobiletools/draw/MyCanvas.kt +++ b/app/src/main/kotlin/com/simplemobiletools/draw/MyCanvas.kt @@ -1,12 +1,18 @@ package com.simplemobiletools.draw +import android.app.Activity import android.content.Context -import android.graphics.* +import android.graphics.Bitmap +import android.graphics.Canvas +import android.graphics.Color +import android.graphics.Paint import android.os.Parcel import android.os.Parcelable import android.util.AttributeSet import android.view.MotionEvent import android.view.View +import com.bumptech.glide.Glide +import com.bumptech.glide.load.DecodeFormat import com.simplemobiletools.commons.extensions.getContrastColor import java.util.* @@ -86,9 +92,19 @@ class MyCanvas(context: Context, attrs: AttributeSet) : View(context, attrs) { return bitmap } - fun drawBitmap(path: String) { - mBackgroundBitmap = BitmapFactory.decodeFile(path) - invalidate() + fun drawBitmap(activity: Activity, path: String) { + Thread({ + mBackgroundBitmap = Glide.with(context) + .load(path) + .asBitmap() + .format(DecodeFormat.PREFER_ARGB_8888) + .fitCenter() + .into(width, height) + .get() + activity.runOnUiThread { + invalidate() + } + }).start() } fun addPath(path: MyPath, options: PaintOptions) { diff --git a/app/src/main/kotlin/com/simplemobiletools/draw/activities/MainActivity.kt b/app/src/main/kotlin/com/simplemobiletools/draw/activities/MainActivity.kt index 4061e3c..73730f8 100644 --- a/app/src/main/kotlin/com/simplemobiletools/draw/activities/MainActivity.kt +++ b/app/src/main/kotlin/com/simplemobiletools/draw/activities/MainActivity.kt @@ -118,7 +118,7 @@ class MainActivity : SimpleActivity(), MyCanvas.PathsChangedListener { my_canvas.mBackgroundBitmap = null Svg.loadSvg(this, File(path), my_canvas) } else if (File(path).isImageSlow()) { - my_canvas.drawBitmap(path) + my_canvas.drawBitmap(this, path) } else { toast(R.string.invalid_file_format) }