package com.honu.giftwise.data;

import android.graphics.Bitmap;
import android.graphics.BitmapFactory;

import java.io.ByteArrayOutputStream;

/**
 * Created by bdiegel on 3/21/15.
 */
public class BitmapUtils {

    // convert from bitmap to byte array
    public static 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 static Bitmap getImage(byte[] image) {
        return BitmapFactory.decodeByteArray(image, 0, image.length);
    }


    public static Bitmap resizeBitmap(Bitmap image, int maxSize) {
        int width = image.getWidth();
        int height = image.getHeight();
        float aspectRatio = width / (float) height;

        if (aspectRatio > 1) {
            width = maxSize;
            height = Math.round(width / aspectRatio);
        } else {
            height = maxSize;
            width = Math.round(height * aspectRatio);
        }

        return Bitmap.createScaledBitmap(image, width, height, true);
    }
}

@@ -26,16 +26,54 @@
 .data;%0A%0A
+import android.content.res.Resources;%0A
 import a
@@ -134,16 +134,157 @@
 Factory;
+%0Aimport android.support.v4.graphics.drawable.RoundedBitmapDrawable;%0Aimport android.support.v4.graphics.drawable.RoundedBitmapDrawableFactory;
 %0A%0Aimport
@@ -1321,11 +1321,244 @@
 );%0A    %7D
+%0A%0A    public static RoundedBitmapDrawable getRoundedBitmapDrawable(Resources res, Bitmap src) %7B%0A        RoundedBitmapDrawable dr = RoundedBitmapDrawableFactory.create(res, src);%0A        dr.setCornerRadius(5);%0A        return dr;%0A    %7D
 %0A%7D%0A

add method to round corners of bitmap drawable