1+ package com.smarttoolfactory.composeimage.demo
2+
3+ import androidx.compose.foundation.background
4+ import androidx.compose.foundation.layout.*
5+ import androidx.compose.material3.MaterialTheme
6+ import androidx.compose.material3.Text
7+ import androidx.compose.runtime.*
8+ import androidx.compose.ui.Modifier
9+ import androidx.compose.ui.graphics.Color
10+ import androidx.compose.ui.graphics.ImageBitmap
11+ import androidx.compose.ui.layout.ContentScale
12+ import androidx.compose.ui.platform.LocalContext
13+ import androidx.compose.ui.res.imageResource
14+ import androidx.compose.ui.text.font.FontWeight
15+ import androidx.compose.ui.unit.dp
16+ import androidx.compose.ui.unit.sp
17+ import com.smarttoolfactory.composeimage.ContentScaleSelectionMenu
18+ import com.smarttoolfactory.composeimage.R
19+ import com.smarttoolfactory.image.zoom.ZoomableImage
20+
21+ @Composable
22+ fun ZoomableImageDemo () {
23+
24+ Column (modifier = Modifier .fillMaxSize()) {
25+ val imageBitmapLarge = ImageBitmap .imageResource(
26+ LocalContext .current.resources,
27+ R .drawable.landscape4
28+ )
29+
30+ var contentScale by remember { mutableStateOf(ContentScale .Fit ) }
31+
32+ ContentScaleSelectionMenu (contentScale = contentScale) {
33+ contentScale = it
34+ }
35+
36+ Text (
37+ text = " clipTransformToContentScale false" ,
38+ fontSize = 16 .sp,
39+ fontWeight = FontWeight .Bold ,
40+ color = MaterialTheme .colorScheme.primary,
41+ modifier = Modifier .padding(8 .dp)
42+ )
43+ ZoomableImage (
44+ modifier = Modifier
45+ .background(Color .LightGray )
46+ .fillMaxWidth()
47+ .aspectRatio(4 / 3f ),
48+ imageBitmap = imageBitmapLarge,
49+ contentScale = contentScale,
50+ clipTransformToContentScale = false
51+ )
52+
53+ Spacer (modifier = Modifier .height(20 .dp))
54+
55+ Text (
56+ text = " clipTransformToContentScale true" ,
57+ fontSize = 16 .sp,
58+ fontWeight = FontWeight .Bold ,
59+ color = MaterialTheme .colorScheme.primary,
60+ modifier = Modifier .padding(8 .dp)
61+ )
62+ ZoomableImage (
63+ modifier = Modifier
64+ .background(Color .LightGray )
65+ .fillMaxWidth()
66+ .aspectRatio(4 / 3f ),
67+ imageBitmap = imageBitmapLarge,
68+ contentScale = contentScale,
69+ clipTransformToContentScale = true
70+ )
71+ }
72+ }
0 commit comments