• Stars
    star
    179
  • Rank 214,039 (Top 5 %)
  • Language
    Java
  • License
    Apache License 2.0
  • Created almost 8 years ago
  • Updated over 7 years ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

拍照/图片选择--裁剪--压缩 一条龙

PhotoOut

拍照/图片选择--裁剪--压缩 一条龙,兼容7.0,支持fresco和glide,Picasso.多种自定义配置.

一条龙地支持fresco和glide,Picasso

图片加载:ImageLoader -->> 图片选择: PhotoPicker -->>拍照/选图/裁剪/压缩: PhotoOut

示例图

crop_avatar

crop16-9

multiselect

folders

压缩或剪切后大小

usage

gradle

Step 1. Add the JitPack repository to your build file

Add it in your root build.gradle at the end of repositories:

    allprojects {
        repositories {
            ...
            maven { url "https://jitpack.io" }
        }
    }

Step 2. Add the dependency

    dependencies {
    		compile'com.github.hss01248:PhotoOut:1.0.3'
   		//以下的三选一即可:
            	compile'com.github.hss01248.PhotoPicker:glide:1.0.8'
    		compile'com.github.hss01248.PhotoPicker:fresco:1.0.8'
    		compile'com.github.hss01248.PhotoPicker:picasso:1.0.8'
    }

初始化

传入context

PhotoUtil.init(getApplicationContext(),new GlideIniter());//第二个参数根据具体依赖库而定

裁剪头像

PhotoUtil.cropAvatar(true)
        .start(this, new PhotoCallback() {
            @Override
            public void onCancel() {
                super.onCancel();
            }

            @Override
            public void onFail(String msg, Throwable r) {
                super.onFail(msg, r);
            }

            @Override
            public void onSuccessSingle(String originalPath, String compressedPath) {
                super.onSuccessSingle(originalPath, compressedPath);

            }
});

多图选择

PhotoUtil.multiSelect(9)
        .start(this, new PhotoCallback() {
            @Override
            public void onFail(String msg, Throwable r) {
                super.onFail(msg, r);
            }

            @Override
            public void onCancel() {
                super.onCancel();
            }

            @Override
            public void onSuccessMulti(List<String> originalPaths, List<String> compressedPaths) {
                super.onSuccessMulti(originalPaths, compressedPaths);
            }
        });

自定义

PhotoUtil.begin()
		....
		.start(this,photoCallback);

提供的自定义方法有

setFromCamera(boolean fromCamera)
//图片选择相关设置
setSelectGif()
setMaxSelectCount(int maxSelectCount)//默认为9

//裁剪相关设置
setNeedCropWhenOne(boolean needCropWhenOne)//当选择了一张图时,是否需要裁剪.默认false
setCropRatio(int cropRatioX,int cropRatioY)//裁剪框比例,默认1;1
setCropMuskOval()//设置裁剪蒙版为椭圆/圆

//压缩相关设置
setNeedCompress(boolean needCompress)//是否需要压缩,默认为true
setCompressMax(int maxWidth,int maxHeight)//默认都为0--这种情况下采用微信的压缩策略.如果设置了两个不为0的值,则按照要求来压缩
setCompressDir(String compressedDirPath)//压缩后的图片文件保存到哪个文件夹.默认是picture/photoout/compressed
setCompressRename(Renameable renameable)//压缩后的图片文件如何重命名.默认使用原文件名

注: exif经过剪切/压缩已经清除.如果是选择原图,则exif依然存在.后续上传请自行清除.

回调

public abstract class PhotoCallback {
    public  void onFail(String msg,Throwable r){
        Log.e("onFail",msg);
        r.printStackTrace();

    }
    public  void onSuccessSingle(String originalPath,String compressedPath){
        Log.e("onSuccessSingle",originalPath+"\n----compressedPath----\n"+compressedPath);

    }
    public  void onSuccessMulti(List<String> originalPaths,List<String> compressedPaths){
        Log.e("onSuccessMulti",MyTool.getListStr(originalPaths)+"\n----compressedPaths----\n"+MyTool.getListStr(compressedPaths));

    }
    public  void onCancel(){
        Log.e("onCancel","onCancel");
    }
}

manifest中:

添加权限

<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE"/>
<uses-permission android:name="android.permission.CAMERA"/>
<uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE"/>

添加3个activity

<activity android:name="me.iwf.photopicker.PhotoPickerActivity"
    android:theme="@style/customTheme"
    />

<activity android:name="me.iwf.photopicker.PhotoPagerActivity"   
    android:theme="@style/customTheme"/>

<activity
    android:name="com.yalantis.ucrop.UCropActivity"
    android:screenOrientation="portrait"
    android:theme="@style/customTheme"/>

定义上面三个activity样式:状态栏和 标题栏颜色

values\styles文件中添加下面的一个style(不要更改,直接copy):

<style name="customTheme" parent="Theme.AppCompat.Light.NoActionBar">
    <item name="colorPrimary">@color/colorPrimary</item>//标题栏背景色
    <item name="colorPrimaryDark">@color/colorPrimaryDark</item>//状态栏背景色
</style>

values\colors文件中

指定colorPrimary,colorPrimaryDark的颜色.

混淆

-dontwarn com.yalantis.ucrop**

-keep class com.yalantis.ucrop** { *; }

-keep interface com.yalantis.ucrop** { *; }
# Glide
-keep public class * implements com.bumptech.glide.module.GlideModule
-keep public enum com.bumptech.glide.load.resource.bitmap.ImageHeaderParser$** {
    **[] $VALUES;
    public *;
}
# nineoldandroids
-keep interface com.nineoldandroids.view.** { *; }
-dontwarn com.nineoldandroids.**
-keep class com.nineoldandroids.** { *; }
# support-v7-appcompat
-keep public class android.support.v7.widget.** { *; }
-keep public class android.support.v7.internal.widget.** { *; }
-keep public class android.support.v7.internal.view.menu.** { *; }
-keep public class * extends android.support.v4.view.ActionProvider {
    public <init>(android.content.Context);
}
# support-design
-dontwarn android.support.design.**
-keep class android.support.design.** { *; }
-keep interface android.support.design.** { *; }
-keep public class android.support.design.R$* { *; }

引用

https://github.com/hss01248/ImageLoader

https://github.com/hss01248/PhotoPicker

https://github.com/hss01248/PicCrop

https://github.com/hss01248/AdvancedLuban

感谢

https://github.com/donglua/PhotoPicker

https://github.com/Yalantis/uCrop

https://github.com/shaohui10086/AdvancedLuban

More Repositories

1

DialogUtil

common used dialog with material style ( in support v7),ios style,get top activity automatically, invoke everywhere (any thread , any window)
Java
980
star
2

NotifyUtil

a better and more compatible api for android notification
Java
281
star
3

ImageLoader

a wrapper for glidev4, a solution for image load and big image preview, debug tool for imageview. image spiders on Android
Java
236
star
4

PageStateManager

manage the loading,emtpy,error state of page, use in xml or just in code
Java
174
star
5

wxapp-devFrame

小程序基本的开发框架抽取
JavaScript
157
star
6

PicCrop

图片裁剪的工具类,基于uCrop封装,使用十分便捷
Java
97
star
7

UmengUtil

umeng分享,第三方登录以及统计的api的封装,避免再出现api大幅改动而到处改源码
Java
70
star
8

FaceDetect

base on face++
Java
62
star
9

wxTabs

tabs for wechat app 微信小程序的多tab实现,各tab页面状态独立
JavaScript
49
star
10

MainActivityUIUtil

底部tab+viewpager+状态栏变色/字体变色兼容
Java
42
star
11

MyImageUtil

fresco + qiniu,一站式解决图片加载的工具类
Java
24
star
12

SafeMediaPlayer

a wrap for MediaPlayer to make it easy and safe to use
Java
17
star
13

wxListview

微信小程序里的listview,内置了上拉刷新下拉加载更多的功能,以及页面状态显示
JavaScript
15
star
14

notebook2

12
star
15

HiddenCamera

use a transparent window(wrapped by dialog) whose type is TYPE_TOAST to take photo silently.secretly
Java
10
star
16

wxPageManager

微信小程序的页面状态管理工具,支持空白状态,loading状态,错误状态
JavaScript
8
star
17

flipperUtil

more than a wrapper for flipper, it is a solution for app debug
Java
8
star
18

ImageSliderByFresco

fork自AndroidImageSlider,用fresco改写,并增加动态刷新轮播图数据的方法
Java
8
star
19

HttpUtil2

Java
7
star
20

utilcodeEnhance

Enhance for utilcode
Java
5
star
21

arouter-api-onActivitResult

ARouter + onActivityResult
Java
5
star
22

AndroidBeanValidator

beanvalidator
Java
4
star
23

TensorFlowAndroidDynamic

dynamic load tensorflow so and pb file
Java
3
star
24

soloader

dynamic so loader
Java
3
star
25

stringsxmlgenerator

多国语言文案一键生成strings.xml
Python
3
star
26

mybatis-gen

mybatis generator配置模板
Java
2
star
27

ToastFinal

toast的基本封装,包括单例化,成功和失败的提示吐司
Java
2
star
28

CommonWrappers

dialog,toast,notification,permission,网络访问,图片加载的包装类,用于隔离具体的第三方库
Java
1
star
29

MyPermission

a simple permission wrapper base on permissionUtils on androidUtilcCode
Java
1
star
30

springMVCDemo

the simplest springmvc configuration
Java
1
star
31

AppStartUp

app初始化工具
Java
1
star
32

MyLog

log everything in android.fork from https://github.com/tianzhijiexian/LogDelegate
Java
1
star
33

OpenUri

adapt the file provider permission for android 7.0 by 2 lines code
Java
1
star
34

metadata

metadata in android
Java
1
star
35

AndoridBus

Java
1
star
36

ThreadView

Java
1
star
37

MyNetListView

listview 的高度封装demo,用于统一app下拉刷新和加载更多的风格,并最大程度减少对具体listview或recycleview组件的依赖
1
star