// Path: app/src/main/java/com/mummyding/app/leisure/LeisureApplication.java
// public class LeisureApplication extends Application {
//     public static Context AppContext = null;
//     @Override
//     public void onCreate() {
//         super.onCreate();
//         AppContext = getApplicationContext();
//         Fresco.initialize(AppContext);
//     }
// }


import android.graphics.Bitmap;
import android.graphics.Canvas;
import android.graphics.Color;
import android.graphics.Matrix;
import android.graphics.Paint;
import android.graphics.PorterDuff;
import android.graphics.PorterDuffXfermode;
import android.graphics.Rect;
import android.graphics.drawable.BitmapDrawable;
import android.graphics.drawable.Drawable;
import android.support.v7.graphics.Palette;
import com.facebook.drawee.view.SimpleDraweeView;
import com.mummyding.app.leisure.LeisureApplication;
package com.mummyding.app.leisure.support;




/**
 * Created by MummyDing on 16-2-10.
 * GitHub: https://github.com/MummyDing
 * Blog: http://blog.csdn.net/mummyding
 */
public class ImageUtil {
    public static int getImageColor(Bitmap bitmap){
        Palette palette = Palette.from(bitmap).generate();
        if(palette == null || palette.getDarkMutedSwatch() == null){
            return Color.LTGRAY;
        }
        return palette.getDarkMutedSwatch().getRgb();
    }

    public static Bitmap getBitmap(SimpleDraweeView imageView){
        Bitmap bitmap;
        if (imageView.getDrawable() instanceof BitmapDrawable) {
            bitmap = ((BitmapDrawable) imageView.getDrawable()).getBitmap();
        } else {
            Drawable d = imageView.getDrawable();
            bitmap = Bitmap.createBitmap(d.getIntrinsicWidth(), d.getIntrinsicHeight(), Bitmap.Config.ARGB_8888);
            Canvas canvas = new Canvas(bitmap);
            d.draw(canvas);
        }
        return bitmap;
    }

    public static Bitmap bitmapToCircle(Bitmap bitmap){
        //处理Bitmap 转成正方形
        Bitmap newBitmap = dealRawBitmap(bitmap);
        //将newBitmap 转换成圆形
// Path: app/src/main/java/com/mummyding/app/leisure/LeisureApplication.java
// public class LeisureApplication extends Application {
//     public static Context AppContext = null;
//     @Override
//     public void onCreate() {
//         super.onCreate();
//         AppContext = getApplicationContext();
//         Fresco.initialize(AppContext);
//     }
// }


// Path: app/src/main/java/com/mummyding/app/leisure/support/ImageUtil.java
import android.graphics.Bitmap;
import android.graphics.Canvas;
import android.graphics.Color;
import android.graphics.Matrix;
import android.graphics.Paint;
import android.graphics.PorterDuff;
import android.graphics.PorterDuffXfermode;
import android.graphics.Rect;
import android.graphics.drawable.BitmapDrawable;
import android.graphics.drawable.Drawable;
import android.support.v7.graphics.Palette;
import com.facebook.drawee.view.SimpleDraweeView;
import com.mummyding.app.leisure.LeisureApplication;

package com.mummyding.app.leisure.support;




/**
 * Created by MummyDing on 16-2-10.
 * GitHub: https://github.com/MummyDing
 * Blog: http://blog.csdn.net/mummyding
 */
public class ImageUtil {
    public static int getImageColor(Bitmap bitmap){
        Palette palette = Palette.from(bitmap).generate();
        if(palette == null || palette.getDarkMutedSwatch() == null){
            return Color.LTGRAY;
        }
        return palette.getDarkMutedSwatch().getRgb();
    }

    public static Bitmap getBitmap(SimpleDraweeView imageView){
        Bitmap bitmap;
        if (imageView.getDrawable() instanceof BitmapDrawable) {
            bitmap = ((BitmapDrawable) imageView.getDrawable()).getBitmap();
        } else {
            Drawable d = imageView.getDrawable();
            bitmap = Bitmap.createBitmap(d.getIntrinsicWidth(), d.getIntrinsicHeight(), Bitmap.Config.ARGB_8888);
            Canvas canvas = new Canvas(bitmap);
            d.draw(canvas);
        }
        return bitmap;
    }

    public static Bitmap bitmapToCircle(Bitmap bitmap){
        //处理Bitmap 转成正方形
        Bitmap newBitmap = dealRawBitmap(bitmap);
        //将newBitmap 转换成圆形
        return toRoundCorner(newBitmap, DisplayUtil.dip2px(LeisureApplication.AppContext,50));