Skip to content

Commit

Permalink
code optimization
Browse files Browse the repository at this point in the history
code optimization
  • Loading branch information
liqi committed Nov 3, 2017
1 parent e176773 commit 3a4c2fa
Show file tree
Hide file tree
Showing 4 changed files with 449 additions and 372 deletions.
43 changes: 43 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,49 @@ OnDisposeOuterListener.startPhoto();
OnDisposeOuterListener.clear()
```

**3:ImageDispose image manipulation tool object, providing a series of static methods to manipulate the image or image path.**<br>

```java
//Converts the input stream into a byte array
ImageDispose.readStream(InputStream inStream);

//Converted to Bitmap by byte array and BitmapFactory
ImageDispose.getPicFromBytes(byte[] bytes,BitmapFactory.Options opts);

//Convert to a specified size Bitmap
ImageDispose.zoomBitmap(Bitmap bitmap, int w, int h);

//Convert bitmap to byte array
ImageDispose.bitmap2Bytes(Bitmap bm, int quality);

//Cut a specified size Bitmap object
ImageDispose.cutterBitmap(Bitmap srcBitmap, int limitWidth,int limitHeight);

//Image compression, return bitmap byte array
ImageDispose.compressBmpFromByte(Bitmap bitmap, long maxsize);

//Image compression, return compressed bitmap
ImageDispose.compressBmpGetBmp(Bitmap bitmap, long maxsize);

//Get the specified size of Bitmap by address, the quality of compression
ImageDispose.acquireBitmap(String path, int compressSize);

//Drawable to Bitmap
ImageDispose.drawableToBitmap(Drawable drawable);

//Drawable The specified size of the zoom
ImageDispose.zoomDrawable(Drawable drawable, int w, int h);

//Byte array conversion File object
ImageDispose.acquireByteFile(byte[] byteOne, String filePath);

//Get the image path to cut out the name of the picture, the path needs to be extended
ImageDispose.getImageName(String path);

//Generate a random unique picture name, the path needs to be extended
ImageDispose.getImageRandomName(String path);
```

6.0 system above need to add their own dynamic permissions
-----
##### If you feel good, please star give me motivation.<br><br>thank you very much.
Expand Down
41 changes: 41 additions & 0 deletions README_CHINESE.md
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,47 @@ OnDisposeOuterListener.startPhoto();
//注:为了防止内存泄漏,请在Activity生命周期onDestroy()调用。
OnDisposeOuterListener.clear()
```
**3:ImageDispose图片操作工具对象,提供一系列静态方法对图片或者图片路径进行操作。**<br>
```java
//通过输入流转换成字节数组
ImageDispose.readStream(InputStream inStream);

//通过字节数组和BitmapFactory转换成Bitmap
ImageDispose.getPicFromBytes(byte[] bytes,BitmapFactory.Options opts);

//转换成指定大小的Bitmap
ImageDispose.zoomBitmap(Bitmap bitmap, int w, int h);

//把bitmap转换成字节数组
ImageDispose.bitmap2Bytes(Bitmap bm, int quality);

//切割指定大小的Bitmap对象
ImageDispose.cutterBitmap(Bitmap srcBitmap, int limitWidth,int limitHeight);

//图片压缩,返回bitmap字节数组
ImageDispose.compressBmpFromByte(Bitmap bitmap, long maxsize);

//图片压缩,返回压缩的bitmap
ImageDispose.compressBmpGetBmp(Bitmap bitmap, long maxsize);

//通过地址获取指定大小的Bitmap(质量压缩)
ImageDispose.acquireBitmap(String path, int compressSize);

//Drawable转Bitmap
ImageDispose.drawableToBitmap(Drawable drawable);

//Drawable 指定大小的缩放
ImageDispose.zoomDrawable(Drawable drawable, int w, int h);

//字节数组转换File对象
ImageDispose.acquireByteFile(byte[] byteOne, String filePath);

//获取图片路径切割出来的图片名字,路径需要带扩展名
ImageDispose.getImageName(String path);

//产生随机唯一图片名称,路径需要带扩展名
ImageDispose.getImageRandomName(String path);
```

6.0系统以上需要自己动态添加权限
-----
Expand Down
25 changes: 6 additions & 19 deletions utils/src/main/java/com/liql/photograph/PhotographDispose.java
Original file line number Diff line number Diff line change
Expand Up @@ -113,13 +113,13 @@ public void run() {
switch (requestCode) {
case SDK_19_BOTTOM:
if (null != data)
file = getFile(new PhotoSDKBottomListener<File>(activity,
file = getFile(new PhotoSDKBottomListener<>(activity,
PhotographDispose.this), data.getData());

break;
case SDK_19_TOP:
if (null != data)
file = getFile(new PhotoSDKTopListener<File>(activity,
file = getFile(new PhotoSDKTopListener<>(activity,
PhotographDispose.this), data.getData());
break;
case SDK_PHOTOGRAPH:
Expand Down Expand Up @@ -200,7 +200,7 @@ public File getPhotographDisposeData(String path) {
if (mPhotographConfigura == null)
return null;

File file = getPath(getImageName(path), mPhotographConfigura.getCompressPath());
File file = getPath(ImageDispose.getImageName(path), mPhotographConfigura.getCompressPath());
// 判断用户选择的图片是否已经压缩过
if (!file.exists()) {
Bitmap bitmap = ImageDispose.acquireBitmap(path, 0, 0);
Expand Down Expand Up @@ -248,33 +248,20 @@ private File getPath(String imageName, String path) {
}
File file = new File(mSystemPath + File.separator + path);
// 判断存储图片的文件夹是否存在
if (!file.exists())
if (!file.exists()) {
file.mkdirs();

}
return new File(file.getPath(), imageName);
}

/**
* 获取图片路径切割出来的图片名字
*
* @param path 图片路径
* @return
*/
private String getImageName(String path) {
String imageName = "";
String[] split = path.split("/");
if (null != split)
imageName = split[split.length - 1];
return imageName;
}

/**
* 获取手机存储图片保存路径
*
* @return
*/
private String getSystemPath() {
String path = "";
String path;
// 判断是否安装有SD卡
if (Environment.getExternalStorageState().equals(
Environment.MEDIA_MOUNTED)) {
Expand Down
Loading

0 comments on commit 3a4c2fa

Please sign in to comment.