Created
March 22, 2023 10:18
-
-
Save trinnguyen/b417eef3e3587dcf7b09242728d69c18 to your computer and use it in GitHub Desktop.
Draw rect drawable to overlay, best for testing Camera Preview
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class RectDrawable(rect: Rect): Drawable() { | |
private val boundingRectPaint = Paint().also { | |
it.style = Paint.Style.STROKE | |
it.color = Color.RED | |
it.strokeWidth = 4f | |
it.alpha = 255 | |
} | |
init { | |
bounds = rect | |
} | |
override fun draw(canvas: Canvas) { | |
canvas.drawRect(bounds, boundingRectPaint) | |
} | |
override fun setAlpha(alpha: Int) { | |
boundingRectPaint.alpha = alpha | |
} | |
override fun setColorFilter(colorFilter: ColorFilter?) { | |
boundingRectPaint.colorFilter = colorFilter | |
} | |
@Deprecated("Deprecated in Java") | |
override fun getOpacity(): Int { | |
return PixelFormat.OPAQUE | |
} | |
companion object { | |
fun ViewGroupOverlay.reloadCodes(items: List<Rect>) { | |
this.clear() | |
items.forEach { | |
this.add(RectDrawable(it)) | |
} | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment