blob: 9902c0074b94e8264261849d2e9b485fafc14fbc [file] [log] [blame]
Aurimas Liutikasac5fe7c2018-03-06 14:40:53 -08001/*
2 * Copyright (C) 2014 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 */
16package androidx.core.graphics;
17
18import android.graphics.Bitmap;
19import android.os.Build;
Aurimas Liutikas9dede512018-03-13 14:08:08 -070020
Aurimas Liutikasac5fe7c2018-03-06 14:40:53 -080021import androidx.annotation.NonNull;
Aurimas Liutikasac5fe7c2018-03-06 14:40:53 -080022
23/**
24 * Helper for accessing features in {@link android.graphics.Bitmap}.
25 */
26public final class BitmapCompat {
Jake Wharton3bbdb0bd2018-03-16 18:12:41 -040027 public static boolean hasMipMap(@NonNull Bitmap bitmap) {
28 if (Build.VERSION.SDK_INT >= 18) {
Aurimas Liutikasac5fe7c2018-03-06 14:40:53 -080029 return bitmap.hasMipMap();
30 }
Jake Wharton3bbdb0bd2018-03-16 18:12:41 -040031 return false;
Aurimas Liutikasac5fe7c2018-03-06 14:40:53 -080032 }
33
34 public static void setHasMipMap(@NonNull Bitmap bitmap, boolean hasMipMap) {
Jake Wharton3bbdb0bd2018-03-16 18:12:41 -040035 if (Build.VERSION.SDK_INT >= 18) {
36 bitmap.setHasMipMap(hasMipMap);
37 }
Aurimas Liutikasac5fe7c2018-03-06 14:40:53 -080038 }
39
40 /**
41 * Returns the size of the allocated memory used to store this bitmap's pixels in a backwards
42 * compatible way.
43 *
44 * @param bitmap the bitmap in which to return its allocation size
45 * @return the allocation size in bytes
46 */
47 public static int getAllocationByteCount(@NonNull Bitmap bitmap) {
Jake Wharton3bbdb0bd2018-03-16 18:12:41 -040048 if (Build.VERSION.SDK_INT >= 19) {
49 return bitmap.getAllocationByteCount();
50 }
51 return bitmap.getByteCount();
Aurimas Liutikasac5fe7c2018-03-06 14:40:53 -080052 }
53
54 private BitmapCompat() {}
Jake Wharton3bbdb0bd2018-03-16 18:12:41 -040055}