mirror of
https://github.com/SimpleMobileTools/Simple-Draw.git
synced 2025-06-05 21:59:17 +02:00
Do color filling on background thread
This commit is contained in:
@ -3,7 +3,6 @@ package com.simplemobiletools.draw.pro.extensions
|
||||
import android.graphics.Bitmap
|
||||
import com.simplemobiletools.draw.pro.helpers.QueueLinearFloodFiller
|
||||
|
||||
|
||||
fun Bitmap.floodFill(color: Int, x: Int, y: Int, tolerance: Int = 10): Bitmap {
|
||||
val floodFiller = QueueLinearFloodFiller(this).apply {
|
||||
fillColor = color
|
||||
|
@ -4,11 +4,9 @@ import android.graphics.Bitmap
|
||||
import android.graphics.Color
|
||||
import java.util.*
|
||||
|
||||
|
||||
// Original algorithm by J. Dunlap http:// www.codeproject.com/KB/GDI-plus/queuelinearflood-fill.aspx
|
||||
// Java port by Owen Kaluza
|
||||
// Android port by Darrin Smith (Standard Android)
|
||||
|
||||
class QueueLinearFloodFiller(img: Bitmap) {
|
||||
|
||||
var image: Bitmap? = null
|
||||
|
@ -3,7 +3,6 @@ package com.simplemobiletools.draw.pro.models
|
||||
import android.graphics.Bitmap
|
||||
import java.io.Serializable
|
||||
|
||||
|
||||
sealed class CanvasOp : Serializable {
|
||||
class PathOp(
|
||||
val path: MyPath,
|
||||
|
@ -393,9 +393,12 @@ class MyCanvas(context: Context, attrs: AttributeSet) : View(context, attrs) {
|
||||
if (contains(touchedX, touchedY)) {
|
||||
val bitmap = getBitmap()
|
||||
val color = mPaintOptions.color
|
||||
val img = bitmap.floodFill(color = color, x = touchedX, y = touchedY)
|
||||
addOperation(CanvasOp.BitmapOp(img))
|
||||
invalidate()
|
||||
|
||||
ensureBackgroundThread {
|
||||
val img = bitmap.floodFill(color = color, x = touchedX, y = touchedY)
|
||||
addOperation(CanvasOp.BitmapOp(img))
|
||||
post { invalidate() }
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@ -408,7 +411,7 @@ class MyCanvas(context: Context, attrs: AttributeSet) : View(context, attrs) {
|
||||
mPath.lineTo(mCurX + 1, mCurY + 2)
|
||||
mPath.lineTo(mCurX + 1, mCurY)
|
||||
}
|
||||
mOperations.add(CanvasOp.PathOp(mPath, mPaintOptions))
|
||||
addOperation(CanvasOp.PathOp(mPath, mPaintOptions))
|
||||
}
|
||||
|
||||
private fun addOperation(operation: CanvasOp) {
|
||||
|
Reference in New Issue
Block a user