-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathImageHelper.java
More file actions
29 lines (22 loc) · 757 Bytes
/
ImageHelper.java
File metadata and controls
29 lines (22 loc) · 757 Bytes
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
package com.foodapp.food.recipe.helper;
import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.graphics.drawable.BitmapDrawable;
import android.graphics.drawable.Drawable;
import java.io.ByteArrayOutputStream;
public class ImageHelper
{
public Bitmap getBitmapFromByteArray(byte[] b)
{
Bitmap bitmap = BitmapFactory.decodeByteArray(b, 0, b.length);
return bitmap;
}
public byte[] getByteArrayFromDrawable(Drawable d)
{
Bitmap bitmap = ((BitmapDrawable) d).getBitmap();
ByteArrayOutputStream stream = new ByteArrayOutputStream();
bitmap.compress(Bitmap.CompressFormat.PNG, 100, stream);
byte[] data = stream.toByteArray();
return data;
}
}