Bitmap target= Bitmap.createBitmap(width, height,Config.ARGB_8888); Canvas canvas = new Canvas(target) float hScale = width/(float)source.getWidth(); float vScale = height/(float)source.getHeight(); float scale = Math.min(hScale, vScale); Matrix matrix = new Matrix(); matrix.setScale(scale, scale); matrix.postTranslate(width/2 - source.getWidth()/2 * scale, height/2 - source.getHeight()/2 * scale); canvas.drawColor(Color.BLACK); canvas.drawBitmap(source, matrix, new Paint());
source share