图片相关API

185 阅读1分钟
   /**
     * 得到指定宽度的图片,高度会等比缩放
     * 原图可能很大,不需要这么大的图片,为了节省内存 ,得到一张小的bitmap
     * @param width
     * @return
     */
    private Bitmap getBitmap(int width) {
        BitmapFactory.Options options = new BitmapFactory.Options();
        options.inJustDecodeBounds = true;
        BitmapFactory.decodeResource(getResources(), R.drawable.bitmap, options);
        options.inJustDecodeBounds = false;
        options.inDensity = options.outWidth;
        options.inTargetDensity = width;
        return BitmapFactory.decodeResource(getResources(), R.drawable.bitmap, options);

    }