center the selected bitmap at drawing

This commit is contained in:
tibbi 2017-04-09 13:03:56 +02:00
parent ca53e9a8d2
commit 6c2dc3ca63
2 changed files with 21 additions and 5 deletions

View File

@ -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,10 +92,20 @@ class MyCanvas(context: Context, attrs: AttributeSet) : View(context, attrs) {
return bitmap
}
fun drawBitmap(path: String) {
mBackgroundBitmap = BitmapFactory.decodeFile(path)
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) {
mPaths.put(path, options)

View File

@ -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)
}