center the selected bitmap at drawing
This commit is contained in:
parent
ca53e9a8d2
commit
6c2dc3ca63
|
@ -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) {
|
||||
|
|
|
@ -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)
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue