Java tutorial
//package com.java2s; //License from project: Apache License import android.graphics.Bitmap; import android.graphics.Canvas; import android.graphics.Matrix; import android.graphics.Paint; public class Main { public static void drawBitmapCenter(Canvas canvas, float f, float f1, float f2, Bitmap bitmap, Paint paint) { drawBitmapCenter(canvas, f, f1, f2, true, true, bitmap, paint); } public static void drawBitmapCenter(Canvas canvas, float f, float f1, float f2, boolean flag, boolean flag1, Bitmap bitmap, Paint paint) { if (flag) { f -= (f2 * (float) bitmap.getWidth()) / 2.0F; } if (flag1) { f1 -= (f2 * (float) bitmap.getHeight()) / 2.0F; } Matrix matrix = new Matrix(); matrix.setScale(f2, f2); matrix.postTranslate(f, f1); canvas.drawBitmap(bitmap, matrix, paint); } }