Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

IDE-127 reduce thumbnail screenshot dimensions #4852

Merged
merged 1 commit into from
Sep 11, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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