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 package com.simplemobiletools.draw
import android.app.Activity
import android.content.Context 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.Parcel
import android.os.Parcelable import android.os.Parcelable
import android.util.AttributeSet import android.util.AttributeSet
import android.view.MotionEvent import android.view.MotionEvent
import android.view.View import android.view.View
import com.bumptech.glide.Glide
import com.bumptech.glide.load.DecodeFormat
import com.simplemobiletools.commons.extensions.getContrastColor import com.simplemobiletools.commons.extensions.getContrastColor
import java.util.* import java.util.*
@ -86,9 +92,19 @@ class MyCanvas(context: Context, attrs: AttributeSet) : View(context, attrs) {
return bitmap return bitmap
} }
fun drawBitmap(path: String) { fun drawBitmap(activity: Activity, path: String) {
mBackgroundBitmap = BitmapFactory.decodeFile(path) Thread({
invalidate() 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) { fun addPath(path: MyPath, options: PaintOptions) {

View File

@ -118,7 +118,7 @@ class MainActivity : SimpleActivity(), MyCanvas.PathsChangedListener {
my_canvas.mBackgroundBitmap = null my_canvas.mBackgroundBitmap = null
Svg.loadSvg(this, File(path), my_canvas) Svg.loadSvg(this, File(path), my_canvas)
} else if (File(path).isImageSlow()) { } else if (File(path).isImageSlow()) {
my_canvas.drawBitmap(path) my_canvas.drawBitmap(this, path)
} else { } else {
toast(R.string.invalid_file_format) toast(R.string.invalid_file_format)
} }