GalleryFinal图片选择器

在AS中导入:

compile 'cn.finalteam:galleryfinal:1.4.6'
compile 'com.github.bumptech.glide:glide:3.5.2'

在MyApplicition中初始化配置:

ThemeConfig theme = new ThemeConfig.Builder()
        .setTitleBarBgColor(Color.parseColor("#ff0000"))
        .setTitleBarTextColor(Color.WHITE)
        .setTitleBarIconColor(Color.WHITE)
        .setCheckSelectedColor(Color.parseColor("#639ddb"))
        .setFabNornalColor(Color.parseColor("#639ddb"))
        .setFabPressedColor(Color.parseColor("#639ddb"))
        .setIconFab(R.mipmap.nim_ic_trans_fail)
        .setIconRotate(R.mipmap.nim_ic_trans_fail)


        .build();
//配置功能
FunctionConfig functionConfig = new FunctionConfig.Builder()
        .setEnableEdit(false)
        .setEnableCrop(false)
        .setEnableRotate(false)
        .setEnableCamera(true)
        .setEnablePreview(true)
        .build();
//配置imageloader
GlideImageLoader imageLoader = new GlideImageLoader();
CoreConfig coreConfig = new CoreConfig.Builder(getApplicationContext(), imageLoader, theme)
        .setFunctionConfig(functionConfig)
        .setEditPhotoCacheFolder(new File(Environment.getExternalStorageDirectory().getPath() + File.separator + getPackageName()))
        .setTakePhotoFolder(new File(Environment.getExternalStorageDirectory().getPath() + File.separator + getPackageName()))
        .setNoAnimcation(true)
        .build();
GalleryFinal.init(coreConfig);



这个是GilderImageLoader类:

public class GlideImageLoader implements cn.finalteam.galleryfinal.ImageLoader {
    @Override
    public void displayImage(Activity activity, String path, final GFImageView imageView, Drawable defaultDrawable, int width, int height) {
        Glide.with(activity)
                .load("file://" + path)
                .override(width, height)
                .diskCacheStrategy(DiskCacheStrategy.NONE) //不缓存到SD卡
                .skipMemoryCache(true)
                        //.centerCrop()
                .into(new ImageViewTarget<GlideDrawable>(imageView) {
                    @Override
                    protected void setResource(GlideDrawable resource) {
                        imageView.setImageDrawable(resource);
                    }


                    @Override
                    public void setRequest(Request request) {
                        imageView.setTag(R.id.adapter_item_tag_key, request);
                    }


                    @Override
                    public Request getRequest() {
                        return (Request) imageView.getTag(R.id.adapter_item_tag_key);
                    }
                });
    }


    @Override
    public void clearMemoryCache() {
    }
}

在values文件下新建ids.xml文件

<resources>
    <item name="adapter_item_tag_key" type="id" />
    <item name="grild_item_tag_key" type="id" />
</resources>


使用时根据需求配置functionConfig 

FunctionConfig functionConfig = new FunctionConfig.Builder()
                .setMutiSelectMaxSize(1)
                .setEnableEdit(false)
                .setEnableCrop(false)
                .setCropWidth(getResources().getDisplayMetrics().widthPixels)
                .setCropHeight(getResources().getDisplayMetrics().widthPixels)
                .setEnableRotate(false)
                .setEnableCamera(false)
                .setEnablePreview(false)
                .setCropSquare(false)
                .setForceCrop(false)
                .setForceCropEdit(false)
                .build();
        GalleryFinal.openGalleryMuti(1006, functionConfig, new GalleryFinal.OnHanlderResultCallback() {
            @Override
            public void onHanlderSuccess(int reqeustCode, List<PhotoInfo> resultList) {
                File file = new File(resultList.get(0).getPhotoPath());
                Bitmap bitmap1 = BitmapFactory.decodeFile(resultList.get(0).getPhotoPath());
                Log.d("TAG0", file.length() + "");
                //如果图片大小大于200kb 进行压缩
                if (file.length() > 200 * 1024) {
                    BitmapFactory.Options option = new BitmapFactory.Options();
                    option.inJustDecodeBounds = true;
                    BitmapFactory.decodeFile(resultList.get(0).getPhotoPath(), option);
                    final int height = option.outHeight;
                    final int width = option.outWidth;
                    int ratio = 1;
                    if (height > 1280 || width > 300) {
                        final int heightRatio = Math.round((float) height / (float) 1280);
                        final int widthRation = Math.round((float) width / (float) 720);
                        ratio = heightRatio > widthRation ? heightRatio : widthRation;
                    }
                    option.inSampleSize = ratio;
                    option.inJustDecodeBounds = false;
                    Bitmap bitmap = BitmapFactory.decodeFile(resultList.get(0).getPhotoPath(), option);
                    int degree = 0;
                    //图片属性
                    try {
                        ExifInterface exifInterface = new ExifInterface(new File(resultList.get(0).getPhotoPath()).getAbsolutePath());
                        int oreentaton = exifInterface.getAttributeInt(ExifInterface.TAG_ORIENTATION, ExifInterface.ORIENTATION_NORMAL);
                        switch (oreentaton) {
                            case ExifInterface.ORIENTATION_ROTATE_90:
                                degree = 90;
                                break;
                            case ExifInterface.ORIENTATION_ROTATE_180:
                                degree = 180;
                                break;
                            case ExifInterface.ORIENTATION_ROTATE_270:
                                degree = 270;
                                break;
                        }
                    } catch (IOException e) {
                        e.printStackTrace();
                    }
                    if (degree == 0) {
                        int sourceWidth = bitmap.getWidth();
                        int sourceHeight = bitmap.getHeight();
                        Matrix matrix = new Matrix();
                        matrix.postRotate(90);
                        // 当进行的不只是平移操作的时候,最后的参数为true,可以进行滤波处理,有助于改善新图像质量
                        Bitmap newBitmap = Bitmap.createBitmap(bitmap, 0, 0, sourceWidth, sourceHeight, matrix, true);
                        File resultFile = new File(Environment.getExternalStorageDirectory().getPath() + File.separator + getPackageName(), UUID.randomUUID() + ".png");
                        try {
                            FileOutputStream fos = new FileOutputStream(resultFile);
                            newBitmap.compress(Bitmap.CompressFormat.JPEG, 90, fos);
                        } catch (FileNotFoundException e) {
                            e.printStackTrace();
                        }
                        Log.d("TAG0", resultFile.length() + "");
                        imag.setImageBitmap(newBitmap);
                    }
                }




            }




            @Override
            public void onHanlderFailure(int requestCode, String errorMsg) {


            }
        });
    }

  • 1
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 1
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值