allow drawing a bitmap as the canvas background

This commit is contained in:
tibbi 2017-04-09 12:23:23 +02:00
parent cc78d65f80
commit 631ef6cb97
2 changed files with 12 additions and 7 deletions

View File

@ -1,10 +1,7 @@
package com.simplemobiletools.draw
import android.content.Context
import android.graphics.Bitmap
import android.graphics.Canvas
import android.graphics.Color
import android.graphics.Paint
import android.graphics.*
import android.os.Parcel
import android.os.Parcelable
import android.util.AttributeSet
@ -26,6 +23,7 @@ class MyCanvas(context: Context, attrs: AttributeSet) : View(context, attrs) {
private var mStartY = 0f
private var mIsSaving = false
private var mIsStrokeWidthBarEnabled = false
private var mDrawBitmapAsBackground: Bitmap? = null
init {
mPath = MyPath()
@ -88,6 +86,11 @@ class MyCanvas(context: Context, attrs: AttributeSet) : View(context, attrs) {
return bitmap
}
fun drawBitmap(path: String) {
mDrawBitmapAsBackground = BitmapFactory.decodeFile(path)
invalidate()
}
fun addPath(path: MyPath, options: PaintOptions) {
mPaths.put(path, options)
pathsUpdated()
@ -96,6 +99,10 @@ class MyCanvas(context: Context, attrs: AttributeSet) : View(context, attrs) {
override fun onDraw(canvas: Canvas) {
super.onDraw(canvas)
if (mDrawBitmapAsBackground != null) {
canvas.drawBitmap(mDrawBitmapAsBackground, 0f, 0f, null)
}
for ((key, value) in mPaths) {
changePaint(value)
canvas.drawPath(key, mPaint)
@ -182,8 +189,6 @@ class MyCanvas(context: Context, attrs: AttributeSet) : View(context, attrs) {
}
MotionEvent.ACTION_MOVE -> actionMove(x, y)
MotionEvent.ACTION_UP -> actionUp()
else -> {
}
}
invalidate()

View File

@ -117,7 +117,7 @@ class MainActivity : SimpleActivity(), MyCanvas.PathsChangedListener {
if (path.endsWith(".svg")) {
Svg.loadSvg(this, File(path), my_canvas)
} else if (File(path).isImageSlow()) {
my_canvas.drawBitmap(path)
} else {
toast(R.string.invalid_file_format)
}