1 /* 2 * Copyright (C) 2019 The Android Open Source Project 3 * 4 * Licensed under the Apache License, Version 2.0 (the "License"); 5 * you may not use this file except in compliance with the License. 6 * You may obtain a copy of the License at 7 * 8 * http://www.apache.org/licenses/LICENSE-2.0 9 * 10 * Unless required by applicable law or agreed to in writing, software 11 * distributed under the License is distributed on an "AS IS" BASIS, 12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 * See the License for the specific language governing permissions and 14 * limitations under the License. 15 */ 16 package com.android.wallpaper.util; 17 18 import android.graphics.Bitmap; 19 import android.graphics.Rect; 20 import android.util.Log; 21 22 /** 23 * Class with different bitmap processors to apply to bitmaps 24 */ 25 public final class BitmapProcessor { 26 27 private static final String TAG = "BitmapProcessor"; 28 private static final int DOWNSAMPLE = 5; 29 BitmapProcessor()30 private BitmapProcessor() { 31 } 32 33 /** 34 * Function that transforms a bitmap into a lower resolution. 35 * 36 * @param bitmap the bitmap we want to blur. 37 * @param outWidth the end width of the blurred bitmap. 38 * @param outHeight the end height of the blurred bitmap. 39 * @return the blurred bitmap. 40 */ createLowResBitmap(Bitmap bitmap, int outWidth, int outHeight)41 public static Bitmap createLowResBitmap(Bitmap bitmap, int outWidth, int outHeight) { 42 try { 43 Rect rect = new Rect(0, 0, bitmap.getWidth(), bitmap.getHeight()); 44 WallpaperCropUtils.fitToSize(rect, outWidth / DOWNSAMPLE, outHeight / DOWNSAMPLE); 45 46 return Bitmap.createScaledBitmap(bitmap, rect.width(), rect.height(), 47 true /* filter */); 48 } catch (IllegalArgumentException ex) { 49 Log.e(TAG, "error while blurring bitmap", ex); 50 } 51 52 return null; 53 } 54 } 55