@@ -0,0 +1,2177 @@
+package com.camnter.newlife.utils;%0A%0Aimport android.content.res.Resources;%0Aimport android.graphics.Bitmap;%0Aimport android.graphics.Canvas;%0Aimport android.graphics.drawable.BitmapDrawable;%0Aimport android.graphics.drawable.Drawable;%0Aimport android.view.View;%0Aimport android.widget.ImageView;%0A%0A/**%0A * Description%EF%BC%9ABitmapUtils%0A * Created by%EF%BC%9ACaMnter%0A * Time%EF%BC%9A2016-02-25 22:23%0A */%0Apublic class BitmapUtils %7B%0A%0A    private BitmapUtils() %7B%0A%0A    %7D%0A%0A    private static final float DENSITY = Resources.getSystem().getDisplayMetrics().density;%0A    private static final Canvas sCanvas = new Canvas();%0A%0A    public static int dp2Px(int dp) %7B%0A        return Math.round(dp * DENSITY);%0A    %7D%0A%0A    /**%0A     * %E9%80%9A%E8%BF%87 View %E5%88%9B%E5%BB%BA Bitmap%0A     *%0A     * @param view view%0A     * @return Bitmap%0A     */%0A    public static Bitmap createBitmapFromView(View view) %7B%0A        if (view instanceof ImageView) %7B%0A            Drawable drawable = ((ImageView) view).getDrawable();%0A            if (drawable != null && drawable instanceof BitmapDrawable) %7B%0A                return ((BitmapDrawable) drawable).getBitmap();%0A            %7D%0A        %7D%0A        view.clearFocus();%0A        Bitmap bitmap = createBitmapSafely(view.getWidth(),%0A                view.getHeight(), Bitmap.Config.ARGB_8888, 1);%0A        if (bitmap != null) %7B%0A            synchronized (sCanvas) %7B%0A                Canvas canvas = sCanvas;%0A                canvas.setBitmap(bitmap);%0A                view.draw(canvas);%0A                canvas.setBitmap(null);%0A            %7D%0A        %7D%0A        return bitmap;%0A    %7D%0A%0A    /**%0A     * %E5%AE%89%E5%85%A8%E5%9C%B0%E5%88%9B%E5%BB%BA Bitmap%0A     *%0A     * @param width      width%0A     * @param height     height%0A     * @param config     config%0A     * @param retryCount retryCount%0A     * @return Bitmap%0A     */%0A    public static Bitmap createBitmapSafely(int width, int height, Bitmap.Config config, int retryCount) %7B%0A        try %7B%0A            return Bitmap.createBitmap(width, height, config);%0A        %7D catch (OutOfMemoryError e) %7B%0A            e.printStackTrace();%0A            if (retryCount %3E 0) %7B%0A                System.gc();%0A                return createBitmapSafely(width, height, config, retryCount - 1);%0A            %7D%0A            return null;%0A        %7D%0A    %7D%0A%0A%7D%0A

add BitmapUtils