Tomáš Válek
unread,May 8, 2024, 2:54:08 AMMay 8Sign in to reply to author
Sign in to forward
You do not have permission to delete messages in this group
Either email addresses are anonymous for this group or you need the view member email addresses permission to view the original message
to Android CameraX Discussion Group, xi...@google.com, Android CameraX Discussion Group, Tomáš Válek
Ad 1. OK, you are right about scaling/cropping. When I used your advice, it helps to show rectangle exactly to the same place like in Ui. Thank you. Rest setup is basic without any extra setup.
previewUseCase = Preview.Builder
().Build()
try {
// Unbind use cases before rebinding
cameraProvider.unbindAll
()
// Order by priority
val useCaseGroup: UseCaseGroup.Builder = UseCaseGroup.Builder
()
previewUseCase?.
let { useCaseGroup.addUseCase
(it) }
val overlayEffect = getOverlayEffect
()
useCaseGroup.addEffect
(overlayEffect
)
cameraProvider.bindToLifecycle(lifecycleOwner, cameraSelector, useCaseGroup.build())
} catch (e: Exception
) {
e.printStackTrace
()
} Ad 2.:
Code: Draw overlay Text + one blue rectangle
val paintText = TextPaint().apply {
color = Color.YELLOW // Set the text color
textSize = titleTextSize.toFloat() // Set the text size
isAntiAlias = true // Smooth out the edges of what is being drawn
}
val paintRect = Paint().apply {
color = Color.BLUE
style = Paint.Style.FILL
alpha = 25 // 0..255
}
canvas.translate
(pivotX
, pivotY
)
val staticLayout = StaticLayout.Builder.obtain
(text
, 0, text.
length, paintText
, staticLayoutWidth
).
apply {
setAlignment
(Layout.Alignment.
ALIGN_NORMAL)
setLineSpacing
(1.0f, 1.0f)
setIncludePad
(false)
}.build
()
staticLayout.draw
(canvas
)
canvas.drawRect
(0f, 0f, 200f, 200f, paintRect
)
Produces different results:
2A.: Pixel 2 Android 12. WRONG: White flashing + overlay repeats text (in place) + blue rectangles problem (I draw only one rectangle).
2B.: Pixel 2 Android 13. WRONG: Overlay repeats text (in place, see seconds) + blue rectangles problem (I draw only one rectangle with alpha 22, so the rectangle is overlaped several times).
Samsung Galaxy S20+ Android 13: WORKS WELL. Text is changed every second, text is not overlaped, blue rectangle is not overlaped, there is only one blue rectangle with correct alpha.
Thank you for your answer.