|
|
@ -1,6 +1,6 @@ |
|
|
|
package example.imageviewer.utils |
|
|
|
package example.imageviewer.utils |
|
|
|
|
|
|
|
|
|
|
|
import androidx.compose.ui.window.WindowSize |
|
|
|
import androidx.compose.ui.unit.DpSize |
|
|
|
import androidx.compose.ui.unit.dp |
|
|
|
import androidx.compose.ui.unit.dp |
|
|
|
import java.awt.Dimension |
|
|
|
import java.awt.Dimension |
|
|
|
import java.awt.Graphics2D |
|
|
|
import java.awt.Graphics2D |
|
|
@ -41,7 +41,7 @@ fun scaleBitmapAspectRatio( |
|
|
|
return result |
|
|
|
return result |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
fun getDisplayBounds(bitmap: BufferedImage, windowSize: WindowSize): Rectangle { |
|
|
|
fun getDisplayBounds(bitmap: BufferedImage, windowSize: DpSize): Rectangle { |
|
|
|
|
|
|
|
|
|
|
|
val boundW: Float = windowSize.width.value.toFloat() |
|
|
|
val boundW: Float = windowSize.width.value.toFloat() |
|
|
|
val boundH: Float = windowSize.height.value.toFloat() |
|
|
|
val boundH: Float = windowSize.height.value.toFloat() |
|
|
@ -123,7 +123,7 @@ fun cropImage(bitmap: BufferedImage, crop: Rectangle) : BufferedImage { |
|
|
|
|
|
|
|
|
|
|
|
fun cropBitmapByScale( |
|
|
|
fun cropBitmapByScale( |
|
|
|
bitmap: BufferedImage, |
|
|
|
bitmap: BufferedImage, |
|
|
|
size: WindowSize, |
|
|
|
size: DpSize, |
|
|
|
scale: Float, |
|
|
|
scale: Float, |
|
|
|
drag: DragHandler |
|
|
|
drag: DragHandler |
|
|
|
): BufferedImage { |
|
|
|
): BufferedImage { |
|
|
@ -143,7 +143,7 @@ fun cropBitmapByScale( |
|
|
|
fun cropBitmapByBounds( |
|
|
|
fun cropBitmapByBounds( |
|
|
|
bitmap: BufferedImage, |
|
|
|
bitmap: BufferedImage, |
|
|
|
bounds: Rectangle, |
|
|
|
bounds: Rectangle, |
|
|
|
size: WindowSize, |
|
|
|
size: DpSize, |
|
|
|
scaleFactor: Float, |
|
|
|
scaleFactor: Float, |
|
|
|
drag: DragHandler |
|
|
|
drag: DragHandler |
|
|
|
): Rectangle { |
|
|
|
): Rectangle { |
|
|
@ -196,11 +196,11 @@ fun cropBitmapByBounds( |
|
|
|
return Rectangle(leftOffset, topOffset, leftOffset + boundW, topOffset + boundH) |
|
|
|
return Rectangle(leftOffset, topOffset, leftOffset + boundW, topOffset + boundH) |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
fun getPreferredWindowSize(desiredWidth: Int, desiredHeight: Int): WindowSize { |
|
|
|
fun getPreferredWindowSize(desiredWidth: Int, desiredHeight: Int): DpSize { |
|
|
|
val screenSize: Dimension = Toolkit.getDefaultToolkit().screenSize |
|
|
|
val screenSize: Dimension = Toolkit.getDefaultToolkit().screenSize |
|
|
|
val preferredWidth: Int = (screenSize.width * 0.8f).toInt() |
|
|
|
val preferredWidth: Int = (screenSize.width * 0.8f).toInt() |
|
|
|
val preferredHeight: Int = (screenSize.height * 0.8f).toInt() |
|
|
|
val preferredHeight: Int = (screenSize.height * 0.8f).toInt() |
|
|
|
val width: Int = if (desiredWidth < preferredWidth) desiredWidth else preferredWidth |
|
|
|
val width: Int = if (desiredWidth < preferredWidth) desiredWidth else preferredWidth |
|
|
|
val height: Int = if (desiredHeight < preferredHeight) desiredHeight else preferredHeight |
|
|
|
val height: Int = if (desiredHeight < preferredHeight) desiredHeight else preferredHeight |
|
|
|
return WindowSize(width.dp, height.dp) |
|
|
|
return DpSize(width.dp, height.dp) |
|
|
|
} |
|
|
|
} |
|
|
|