Code Monkey home page Code Monkey logo

takephoto's Introduction

TakePhoto 简介

  • 支持以拍照的方式获取照片
  • 支持从相册选择照片
  • 支持对照片进行裁切
  • 支持对照片进行压缩
  • 支持对裁切及压缩参数自定义
  • 支持因拍照Activity被回收后的自动恢复

GitHub地址: https://github.com/crazycodeboy/TakePhoto ##如何使用
###使用TakePhoto有以下两种方式: 方式一:通过继承的方式

  1. 继承TakePhotoActivity、TakePhotoFragmentActivity、TakePhotoFragment三者之一。
  2. 通过getTakePhoto()获取TakePhoto实例进行相关操作。
  3. 重写以下方法获取结果
void takeSuccess(String imagePath);  
void takeFail(String msg);
void takeCancel();

此方式使用简单,满足的大部分的使用需求,具体使用详见simple。如果通过继承的方式无法满足实际项目的使用,可以通过下面介绍的方式。

方式二:通过组装的方式

  1. 获取TakePhoto实例TakePhoto takePhoto=new TakePhotoImpl(getActivity(),this);
  2. onCreate,onActivityResult,onSaveInstanceState方法中调用TakePhoto对用的方法。
  3. 调用TakePhoto实例进行相关操作。
  4. TakeResultListener相关方法中获取结果。
    ###关于压缩照片 你可以选择是否对照片进行压缩处理。
 /**
  * 启用照片压缩
  * @param config 压缩照片配置
  * @param showCompressDialog 压缩时是否显示进度对话框
  * @return 
  */
 TakePhoto onEnableCompress(CompressConfig config,boolean showCompressDialog);

eg:
getTakePhoto().onEnableCompress(new CompressConfig.Builder().setMaxSize(50*1024).setMaxPixel(800).create(),true).onPicSelectCrop(imageUri);
如果你启用了照片压缩,TakePhoto会使用CompressImage对照片进行压缩处理,CompressImage目前支持对照片的尺寸以及照片的质量进行压缩。默认情况下,CompressImage开启了尺寸与质量双重压缩, 你可以通过CompressConfig.Builder对照片压缩后的尺寸以及质量进行相关设置。如果你想改变压缩的方式可以通过CompressConfig.Builder进行相关设置。
##关于兼容性问题
TakePhoto是基于Android官方标准API编写的,适配了目前市场上主流的Rom。如果你在使用过程中发现了适配问题,可以提交Issues。

  1. 为适配部分手机拍照时会回收Activity,TakePhoto在onSaveInstanceStateonCreate做了相应的恢复处理。
  2. 为适配部分手机拍照或从相册选择照片时屏幕方向会发生转变,从而导致拍照失败的问题,可以在AndroidManifest.xml中对使用了TakePhoto的Activity添加android:configChanges="orientation|keyboardHidden|screenSize"配置。
    eg:
<activity
    android:name=".MainActivity"
    android:screenOrientation="portrait"
    android:configChanges="orientation|keyboardHidden|screenSize"
    android:label="@string/app_name" >
    <intent-filter>
        <action android:name="android.intent.action.MAIN" />
        <category android:name="android.intent.category.LAUNCHER" />
    </intent-filter>
</activity>

##在项目中使用
为方便大家使用,现已将TakePhoto发布到JCenter(如果你对如何将项目发布到JCenter感兴趣可以参考:《教你轻松将Android library 发布到JCenter)》
Gradle:

    compile 'com.jph.takephoto:takephoto_library:1.0.1'

Maven:

<dependency>
  <groupId>com.jph.takephoto</groupId>
  <artifactId>takephoto_library</artifactId>
  <version>1.0.1</version>
  <type>pom</type>
</dependency>

##最后
如果你对TakePhoto有更好的建议或想改造它,欢迎大家Fork and Pull requests。

takephoto's People

Contributors

crazycodeboy avatar

Watchers

James Cloos avatar xiongxiaolong avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.