-
Notifications
You must be signed in to change notification settings - Fork 0
/
BitmapManager.java
33 lines (26 loc) · 987 Bytes
/
BitmapManager.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
package com.example.cosmic.androidappclasses;
import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.graphics.drawable.BitmapDrawable;
import android.graphics.drawable.Drawable;
import android.media.ThumbnailUtils;
import java.io.ByteArrayOutputStream;
/**
* Created by ${cosmic} on 1/2/18.
*/
public class BitmapManager {
// convert from bitmap to byte array
public byte[] getBytes(Bitmap bitmap) {
ByteArrayOutputStream stream = new ByteArrayOutputStream();
bitmap.compress(Bitmap.CompressFormat.PNG, 0, stream);
return stream.toByteArray();
}
// convert from byte array to bitmap
public Bitmap getImage(byte[] image) {
return BitmapFactory.decodeByteArray(image, 0, image.length);
}
public Bitmap DrawabletoBitmapthumpnail(Drawable drawable){
BitmapDrawable bitD = (BitmapDrawable) drawable;
return ThumbnailUtils.extractThumbnail(bitD.getBitmap(), 200, 200);
}
}