Skip to content

Commit

Permalink
IDE-127 reduce thumbnail screenshot dimensions
Browse files Browse the repository at this point in the history
  • Loading branch information
Toml499 committed Aug 3, 2023
1 parent 9d29597 commit 6da0313
Showing 1 changed file with 12 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,8 @@ class ScreenshotSaver(
companion object {
private val TAG = ScreenshotSaver::class.java.simpleName
private const val IMAGE_QUALITY = 100
private const val MAX_SCREEN_SHOT_HEIGHT = 480
private const val MAX_SCREEN_SHOT_WIDTH = 480
private const val NUMBER_OF_COLORS = 4
private val VALID_FILENAME_REGEX = Regex("^[^<>:;,?\"*|/]+\$")
private val ONLY_WHITESPACE_REGEX = Regex("\\s*")
Expand Down Expand Up @@ -100,19 +102,27 @@ class ScreenshotSaver(
Bitmap.Config.ARGB_8888
)

val aspectRatio = width/height.toDouble()
var newWidth = (MAX_SCREEN_SHOT_HEIGHT * aspectRatio).toInt()
if (newWidth > MAX_SCREEN_SHOT_WIDTH) {
newWidth = MAX_SCREEN_SHOT_WIDTH
}

val resizedBitMap = Bitmap.createScaledBitmap(fullScreenBitmap, newWidth, MAX_SCREEN_SHOT_HEIGHT, false)

val imageScene = gdxFileHandler.absolute(folder + fileName)
val streamScene = imageScene.write(false)
try {
File(folder + Constants.NO_MEDIA_FILE).createNewFile()
fullScreenBitmap.compress(Bitmap.CompressFormat.PNG, IMAGE_QUALITY, streamScene)
resizedBitMap.compress(Bitmap.CompressFormat.PNG, IMAGE_QUALITY, streamScene)
streamScene.close()

if (ProjectManager.getInstance().currentProject != null) {
val projectFolder = ProjectManager.getInstance().currentProject.directory.absolutePath + "/"
val imageProject = gdxFileHandler.absolute(projectFolder + fileName)
val streamProject = imageProject.write(false)
File(projectFolder + Constants.NO_MEDIA_FILE).createNewFile()
fullScreenBitmap.compress(Bitmap.CompressFormat.PNG, IMAGE_QUALITY, streamProject)
resizedBitMap.compress(Bitmap.CompressFormat.PNG, IMAGE_QUALITY, streamProject)
streamProject.close()
}
} catch (e: IOException) {
Expand Down

0 comments on commit 6da0313

Please sign in to comment.