Advertisement
Guest User

CapturableScreen

a guest
Jul 18th, 2022
78
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.54 KB | None | 0 0
  1.  
  2. @Composable
  3. fun CapturableScreen() {
  4. val captureController = rememberCaptureController()
  5. Column(modifier = Modifier.fillMaxSize()) {
  6. Button(onClick = { captureController.capture() }) {
  7. Text(text = "Take screenshot")
  8. }
  9. CapturableScreen(captureController)
  10. }
  11. }
  12.  
  13. @Composable
  14. private fun CapturableScreen(
  15. captureController: CaptureController,
  16. postCreationViewModel: PostCreationViewModel = viewModel()
  17. ) {
  18. Capturable(
  19. controller = captureController,
  20. onCaptured = { bitmap, error ->
  21. if (bitmap != null) {
  22. Utils.saveImage(bitmap.asAndroidBitmap())
  23. }
  24.  
  25. if (error != null) {
  26. Log.e("CaptureError", "Error: ${error.message} ${error.stackTrace.joinToString()}")
  27. }
  28. }
  29. ) {
  30. Content()
  31. }
  32. }
  33.  
  34. @Composable
  35. private fun Content() {
  36. val scrollState = rememberScrollState()
  37.  
  38. val text = remember {
  39. "Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor " +
  40. "incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis" +
  41. " nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat." +
  42. " Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore" +
  43. " eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt" +
  44. " in culpa qui officia deserunt mollit anim id est laborum."
  45. }
  46.  
  47. Column(
  48. verticalArrangement = Arrangement.Center,
  49. horizontalAlignment = Alignment.CenterHorizontally,
  50. modifier = Modifier
  51. .fillMaxSize()
  52. .background(Color.White)
  53. .verticalScroll(scrollState)
  54. ) {
  55. Text(
  56. text = text,
  57. color = Color.Black,
  58. fontSize = 18.sp,
  59. )
  60. Box(
  61. modifier = Modifier
  62. .size(100.dp)
  63. .background(Color.Black)
  64. )
  65. Text(
  66. text = text,
  67. color = Color.Black,
  68. fontSize = 18.sp,
  69. )
  70. Box(
  71. modifier = Modifier
  72. .size(100.dp)
  73. .background(Color.Black)
  74. )
  75. Text(
  76. text = text,
  77. color = Color.Black,
  78. fontSize = 18.sp,
  79. )
  80. Box(
  81. modifier = Modifier
  82. .size(100.dp)
  83. .background(Color.Black)
  84. )
  85. }
  86. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement