图片优化

图片的格式

Android原生平台支持图片格式主要有JEPG,PNG,GIF,BMP,WebP
在开发中能够使用的只有三种:JEPG,PNG,WebP

图片的压缩

搭建界面时使用的几乎是PNG格式,
对PNG压缩达到瘦身的目的

无损压缩imageOptim

有损压缩imageAlpha

有损压缩TinyPNG

PNG/JEPG转换为WebP

尽量使用NinePatch格式的PNG图

高德将view转成bitmap

    public static BitmapDescriptor fromView(View var0) {
        try {
            Context var1 = p.a;
            if(var1 != null) {
                FrameLayout var2 = new FrameLayout(var1);
                var2.addView(var0);
                var2.setDrawingCacheEnabled(true);
                Bitmap var3 = en.a(var2);
                BitmapDescriptor var4 = fromBitmap(var3);
                var3.recycle();
                return var4;
            } else {
                return null;
            }
        } catch (Throwable var5) {
            return null;
        }
    }
    public static Bitmap a(View var0) {
        try {
            b(var0);
            var0.destroyDrawingCache();
            var0.measure(MeasureSpec.makeMeasureSpec(0, 0), MeasureSpec.makeMeasureSpec(0, 0));
            var0.layout(0, 0, var0.getMeasuredWidth(), var0.getMeasuredHeight());
            Bitmap var1 = var0.getDrawingCache();
            return var1 != null?var1.copy(Config.ARGB_8888, false):null;
        } catch (Throwable var2) {
            ft.b(var2, "Utils", "getBitmapFromView");
            var2.printStackTrace();
            return null;
        }
    }
    private static void b(View var0) {
        if(var0 instanceof ViewGroup) {
            for(int var1 = 0; var1 < ((ViewGroup)var0).getChildCount(); ++var1) {
                b(((ViewGroup)var0).getChildAt(var1));
            }
        } else if(var0 instanceof TextView) {
            ((TextView)var0).setHorizontallyScrolling(false);
        }

    }

bitmap的六种压缩方式,Android图片压缩

你可能感兴趣的:(图片优化)