can display and zoom an image
parent
c758d0b79d
commit
b4ab91e1db
|
|
@ -2,9 +2,14 @@ plugins {
|
||||||
id("org.jetbrains.compose") version "1.5.11"
|
id("org.jetbrains.compose") version "1.5.11"
|
||||||
}
|
}
|
||||||
|
|
||||||
|
repositories {
|
||||||
|
google()
|
||||||
|
}
|
||||||
|
|
||||||
dependencies {
|
dependencies {
|
||||||
implementation("org.pushing-pixels:aurora-theming:1.3.0")
|
implementation("org.pushing-pixels:aurora-theming:1.3.0")
|
||||||
implementation("org.pushing-pixels:aurora-component:1.3.0")
|
implementation("org.pushing-pixels:aurora-component:1.3.0")
|
||||||
implementation("org.pushing-pixels:aurora-window:1.3.0")
|
implementation("org.pushing-pixels:aurora-window:1.3.0")
|
||||||
implementation(compose.desktop.currentOs)
|
implementation(compose.desktop.currentOs)
|
||||||
|
implementation("io.github.panpf.zoomimage:zoomimage-compose:1.0.0-beta11")
|
||||||
}
|
}
|
||||||
|
|
@ -1,20 +1,32 @@
|
||||||
package de.itkl.documentViewer
|
package de.itkl.documentViewer
|
||||||
|
|
||||||
|
import androidx.compose.foundation.Image
|
||||||
import androidx.compose.foundation.layout.Arrangement
|
import androidx.compose.foundation.layout.Arrangement
|
||||||
import androidx.compose.foundation.layout.Row
|
import androidx.compose.foundation.layout.Row
|
||||||
import androidx.compose.foundation.layout.fillMaxSize
|
import androidx.compose.foundation.layout.fillMaxSize
|
||||||
import androidx.compose.runtime.getValue
|
import androidx.compose.foundation.layout.width
|
||||||
import androidx.compose.runtime.mutableStateOf
|
import androidx.compose.runtime.*
|
||||||
import androidx.compose.runtime.remember
|
|
||||||
import androidx.compose.runtime.setValue
|
|
||||||
import androidx.compose.ui.text.ExperimentalTextApi
|
import androidx.compose.ui.text.ExperimentalTextApi
|
||||||
import androidx.compose.ui.Alignment
|
import androidx.compose.ui.Alignment
|
||||||
import androidx.compose.ui.Modifier
|
import androidx.compose.ui.Modifier
|
||||||
|
import androidx.compose.ui.graphics.ImageBitmap
|
||||||
|
import androidx.compose.ui.graphics.painter.BitmapPainter
|
||||||
|
import androidx.compose.ui.graphics.painter.Painter
|
||||||
|
import androidx.compose.ui.layout.ContentScale
|
||||||
|
import androidx.compose.ui.res.loadImageBitmap
|
||||||
|
import androidx.compose.ui.res.painterResource
|
||||||
import androidx.compose.ui.unit.DpSize
|
import androidx.compose.ui.unit.DpSize
|
||||||
import androidx.compose.ui.unit.dp
|
import androidx.compose.ui.unit.dp
|
||||||
import androidx.compose.ui.window.WindowPlacement
|
import androidx.compose.ui.window.WindowPlacement
|
||||||
import androidx.compose.ui.window.WindowPosition
|
import androidx.compose.ui.window.WindowPosition
|
||||||
import androidx.compose.ui.window.rememberWindowState
|
import androidx.compose.ui.window.rememberWindowState
|
||||||
|
import com.github.panpf.zoomimage.ZoomImage
|
||||||
|
import com.github.panpf.zoomimage.compose.ZoomState
|
||||||
|
import com.github.panpf.zoomimage.compose.rememberZoomState
|
||||||
|
import com.github.panpf.zoomimage.compose.subsampling.fromResource
|
||||||
|
import com.github.panpf.zoomimage.subsampling.ImageSource
|
||||||
|
import kotlinx.coroutines.Dispatchers
|
||||||
|
import kotlinx.coroutines.withContext
|
||||||
import org.pushingpixels.aurora.component.model.Command
|
import org.pushingpixels.aurora.component.model.Command
|
||||||
import org.pushingpixels.aurora.component.projection.CommandButtonProjection
|
import org.pushingpixels.aurora.component.projection.CommandButtonProjection
|
||||||
import org.pushingpixels.aurora.theming.auroraBackground
|
import org.pushingpixels.aurora.theming.auroraBackground
|
||||||
|
|
@ -22,6 +34,9 @@ import org.pushingpixels.aurora.theming.marinerSkin
|
||||||
import org.pushingpixels.aurora.window.AuroraWindow
|
import org.pushingpixels.aurora.window.AuroraWindow
|
||||||
import org.pushingpixels.aurora.window.AuroraWindowTitlePaneConfigurations
|
import org.pushingpixels.aurora.window.AuroraWindowTitlePaneConfigurations
|
||||||
import org.pushingpixels.aurora.window.auroraApplication
|
import org.pushingpixels.aurora.window.auroraApplication
|
||||||
|
import java.io.File
|
||||||
|
import java.io.IOException
|
||||||
|
import java.nio.file.Paths
|
||||||
|
|
||||||
class DocumentViewer {
|
class DocumentViewer {
|
||||||
}
|
}
|
||||||
|
|
@ -36,7 +51,7 @@ fun main() = auroraApplication {
|
||||||
|
|
||||||
AuroraWindow(
|
AuroraWindow(
|
||||||
skin = marinerSkin(),
|
skin = marinerSkin(),
|
||||||
title = "Aurora Demo",
|
title = "Document Viewer",
|
||||||
state = state,
|
state = state,
|
||||||
windowTitlePaneConfiguration = AuroraWindowTitlePaneConfigurations.AuroraPlain(),
|
windowTitlePaneConfiguration = AuroraWindowTitlePaneConfigurations.AuroraPlain(),
|
||||||
onCloseRequest = ::exitApplication
|
onCloseRequest = ::exitApplication
|
||||||
|
|
@ -48,12 +63,51 @@ fun main() = auroraApplication {
|
||||||
verticalAlignment = Alignment.CenterVertically,
|
verticalAlignment = Alignment.CenterVertically,
|
||||||
modifier = Modifier.fillMaxSize().auroraBackground()
|
modifier = Modifier.fillMaxSize().auroraBackground()
|
||||||
) {
|
) {
|
||||||
CommandButtonProjection(
|
AsyncImage(
|
||||||
contentModel = Command(
|
load = { loadImageBitmap(File("assets/xs-reg/00001.jpg")) },
|
||||||
text = text,
|
painterFor = { remember { BitmapPainter(it) } },
|
||||||
action = { text = "Hello, Desktop!" }
|
contentDescription = "Sample",
|
||||||
)
|
modifier = Modifier.fillMaxSize()
|
||||||
).project()
|
|
||||||
|
)
|
||||||
|
// CommandButtonProjection(
|
||||||
|
// contentModel = Command(
|
||||||
|
// text = text,
|
||||||
|
// action = { text = "Hello, Desktop!" }
|
||||||
|
// )
|
||||||
|
// ).project()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@Composable
|
||||||
|
fun <T> AsyncImage(
|
||||||
|
load: suspend () -> T,
|
||||||
|
painterFor: @Composable (T) -> Painter,
|
||||||
|
contentDescription: String,
|
||||||
|
modifier: Modifier = Modifier,
|
||||||
|
contentScale: ContentScale = ContentScale.Fit,
|
||||||
|
) {
|
||||||
|
val image: T? by produceState<T?>(null) {
|
||||||
|
value = withContext(Dispatchers.IO) {
|
||||||
|
try {
|
||||||
|
load()
|
||||||
|
} catch (e: IOException) {
|
||||||
|
// instead of printing to console, you can also write this to log,
|
||||||
|
// or show some error placeholder
|
||||||
|
e.printStackTrace()
|
||||||
|
null
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (image != null) {
|
||||||
|
ZoomImage(
|
||||||
|
painter = painterFor(image!!),
|
||||||
|
contentDescription = contentDescription,
|
||||||
|
contentScale = contentScale,
|
||||||
|
modifier = modifier
|
||||||
|
)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
fun loadImageBitmap(file: File): ImageBitmap =
|
||||||
|
file.inputStream().buffered().use(::loadImageBitmap)
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue