diff --git a/library/src/androidMain/kotlin/ir/mahozad/multiplatform/comshot/Comshot.android.kt b/library/src/androidMain/kotlin/ir/mahozad/multiplatform/comshot/Comshot.android.kt index 12d0a6b..87a9246 100644 --- a/library/src/androidMain/kotlin/ir/mahozad/multiplatform/comshot/Comshot.android.kt +++ b/library/src/androidMain/kotlin/ir/mahozad/multiplatform/comshot/Comshot.android.kt @@ -10,22 +10,18 @@ import android.os.* import android.view.* import androidx.annotation.DoNotInline import androidx.annotation.RequiresApi -import androidx.compose.foundation.background -import androidx.compose.foundation.layout.Box -import androidx.compose.foundation.layout.size import androidx.compose.runtime.* import androidx.compose.ui.InternalComposeUiApi -import androidx.compose.ui.Modifier import androidx.compose.ui.geometry.Offset -import androidx.compose.ui.graphics.Color import androidx.compose.ui.graphics.ImageBitmap import androidx.compose.ui.graphics.asImageBitmap import androidx.compose.ui.platform.* import androidx.compose.ui.semantics.SemanticsNode import androidx.compose.ui.semantics.SemanticsProperties import androidx.compose.ui.test.* -import androidx.compose.ui.unit.dp import androidx.compose.ui.window.DialogWindowProvider +import androidx.lifecycle.Lifecycle +import androidx.lifecycle.LifecycleObserver import androidx.test.platform.app.InstrumentationRegistry import androidx.test.platform.graphics.HardwareRendererCompat import kotlinx.coroutines.Dispatchers @@ -44,7 +40,6 @@ actual fun setContenttt(content: @Composable () -> Unit): Unit = TODO() actual fun captureToImageeee(content: @Composable () -> Unit): ImageBitmap = TODO() -fun Context.captureToImageeee(comcon: CompositionContext, content: @Composable () -> Unit): ImageBitmap { fun Activity.captureToImageeee(comcon: CompositionContext, content: @Composable () -> Unit): ImageBitmap { ////////////////////////////////////////////////// ////////////////////////////////////////////////// @@ -80,7 +75,8 @@ fun Activity.captureToImageeee(comcon: CompositionContext, content: @Composable ////////////////////////////////////////////////// ////////////////////////////////////////////////// // LocalView.current - // LayoutInflater inflater = (LayoutInflater) this.getSystemService(Context.LAYOUT_INFLATER_SERVICE); + // val inflater = getSystemService(Context.LAYOUT_INFLATER_SERVICE) as LayoutInflater + // val composeView = inflater.inflate(R.layout.temppp, findViewById(android.R.id.content), false) as ComposeView val composeView = ComposeView(this) val recomposer = Recomposer(Dispatchers.Unconfined) composeView.setParentCompositionContext(recomposer) @@ -93,8 +89,8 @@ fun Activity.captureToImageeee(comcon: CompositionContext, content: @Composable composeView.setContent(content) // composeView.setBackgroundColor(android.graphics.Color.BLUE) composeView.measure( - View.MeasureSpec.makeMeasureSpec(300, View.MeasureSpec.EXACTLY), - View.MeasureSpec.makeMeasureSpec(300, View.MeasureSpec.EXACTLY), + View.MeasureSpec.makeMeasureSpec(500, View.MeasureSpec.EXACTLY), + View.MeasureSpec.makeMeasureSpec(500, View.MeasureSpec.EXACTLY), ) composeView.layout( 0, diff --git a/library/src/commonMain/kotlin/ir/mahozad/multiplatform/comshot/Comshot.kt b/library/src/commonMain/kotlin/ir/mahozad/multiplatform/comshot/Comshot.kt index e6597a7..06dd9c1 100644 --- a/library/src/commonMain/kotlin/ir/mahozad/multiplatform/comshot/Comshot.kt +++ b/library/src/commonMain/kotlin/ir/mahozad/multiplatform/comshot/Comshot.kt @@ -19,7 +19,7 @@ // https://stackoverflow.com/questions/63861095/jetpack-compose-take-screenshot-of-composable-function // https://stackoverflow.com/questions/74450838/convert-a-composable-view-into-image-in-jetpack-compose // https://stackoverflow.com/questions/76606244/how-to-take-a-full-screenshot-capture-in-android-compose -// https://stackoverflow.com/questions/76283419/using-jetpack-compose-desktop-how-can-i-render-to-an-image-without-a-window/76817459#comment137184179_76817459 +// https://stackoverflow.com/questions/76283419/using-jetpack-compose-desktop-how-can-i-render-to-an-image-without-a-window // https://stackoverflow.com/questions/53529300/rendering-to-an-offscreen-view-and-saving-a-screenshot // https://stackoverflow.com/questions/68355969/take-screenshot-of-a-composable-fun-programmatically-in-jetpack-compose // https://stackoverflow.com/questions/69388898/taking-screenshot-of-webview-androidview-in-jetpack-compose @@ -28,6 +28,11 @@ // https://stackoverflow.com/questions/70944722/composable-to-bitmap-without-displaying-it // https://stackoverflow.com/questions/75461048/how-to-renderor-convert-a-composable-to-image-in-compose-desktop // https://stackoverflow.com/questions/5604125/android-taking-screenshot-of-offscreen-page +// https://stackoverflow.com/questions/7854664/render-view-to-bitmap-off-screen-in-android +// https://stackoverflow.com/questions/4346710/bitmap-from-view-not-displayed-on-android +// https://stackoverflow.com/questions/1240967/draw-inflated-layout-xml-on-an-bitmap +// https://stackoverflow.com/questions/9062015/create-bitmap-of-layout-that-is-off-screen +// https://stackoverflow.com/questions/2661536/how-to-programmatically-take-a-screenshot-on-android /** * The compose-multiplatform-core/compose/ui/ui-test-junit4 depends on compose-multiplatform-core/compose/ui/ui-test