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 
17 package com.android.bluetooth.avrcpcontroller;
18 
19 import android.graphics.Bitmap;
20 import android.graphics.BitmapFactory;
21 
22 import java.io.InputStream;
23 
24 /**
25  * An image object sent over BIP.
26  *
27  * The image is sent as bytes in the payload of a GetImage request. The format of those bytes is
28  * determined by the BipImageDescriptor used when making the request.
29  */
30 public class BipImage {
31     private final String mImageHandle;
32     private Bitmap mImage = null;
33 
BipImage(String imageHandle, InputStream inputStream)34     public BipImage(String imageHandle, InputStream inputStream) {
35         mImageHandle = imageHandle;
36         parse(inputStream);
37     }
38 
BipImage(String imageHandle, Bitmap image)39     public BipImage(String imageHandle, Bitmap image) {
40         mImageHandle = imageHandle;
41         mImage = image;
42     }
43 
parse(InputStream inputStream)44     private void parse(InputStream inputStream) {
45         // BitmapFactory can handle BMP, GIF, JPEG, PNG, WebP, and HEIF formats. Returns null if
46         // the stream couldn't be parsed.
47         mImage = BitmapFactory.decodeStream(inputStream);
48     }
49 
getImageHandle()50     public String getImageHandle() {
51         return mImageHandle;
52     }
53 
getImage()54     public Bitmap getImage() {
55         return mImage;
56     }
57 }
58