Created
June 11, 2019 16:03
-
-
Save hsiaoer/357123fcb2cea77798475dfba7e76905 to your computer and use it in GitHub Desktop.
Scale the sky result bitmap
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Scale the bitmap to fit the view port | |
float scaleWidth = ((float) cameraSize.getWidth()) / notSkyBitmap.getWidth(); | |
float scaleHeight = ((float) cameraSize.getWidth()) / notSkyBitmap.getHeight(); | |
final Matrix matrix = new Matrix(); | |
float scale = Math.min(scaleWidth, scaleHeight); | |
matrix.postScale(scale, scale); | |
// Create a scaled bitmap | |
Bitmap scaledNonSkyBitmap = Bitmap.createBitmap(notSkyBitmap, 0, 0, | |
notSkyBitmap.getWidth(), notSkyBitmap.getHeight(), matrix, false); | |
// Draw the bitmap in bottom center. | |
int left = (cameraSize.getWidth() - scaledNonSkyBitmap.getWidth()) / 2; | |
int top = cameraSize.getHeight() - scaledNonSkyBitmap.getHeight(); | |
canvas.drawBitmap(scaledNonSkyBitmap, left, top, new Paint()); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment