Skip to content

Instantly share code, notes, and snippets.

@hsiaoer
Created June 11, 2019 16:03
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save hsiaoer/357123fcb2cea77798475dfba7e76905 to your computer and use it in GitHub Desktop.
Save hsiaoer/357123fcb2cea77798475dfba7e76905 to your computer and use it in GitHub Desktop.
Scale the sky result bitmap
// 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