Skip to content

Commit

Permalink
图片压缩方案调整
Browse files Browse the repository at this point in the history
  • Loading branch information
r17171709 committed Dec 21, 2017
1 parent ddfed68 commit 17f328e
Show file tree
Hide file tree
Showing 6 changed files with 48 additions and 24 deletions.
5 changes: 4 additions & 1 deletion ImageLibrary/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -35,11 +35,14 @@ dependencies {
testImplementation 'junit:junit:4.12'
androidTestImplementation 'com.android.support.test:runner:1.0.1'
androidTestImplementation 'com.android.support.test.espresso:espresso-core:3.0.1'
compile 'com.github.r17171709:AndroidCommonLibrary:v1.8.3'
compile 'com.github.r17171709:AndroidCommonLibrary:v1.9.2'
// PhotoDraweeView PhotoView For Fresco
compile 'me.relex:photodraweeview:1.1.3'
// uCrop Image Cropping Library for Android
compile 'com.github.yalantis:ucrop:2.2.1'
// subsampling-scale-image-view Highly configurable, easily extendable view with pan and zoom gestures for displaying huge images without loss of detail. Perfect for photo galleries, maps, building plans etc.
compile 'com.davemorrissey.labs:subsampling-scale-image-view:3.9.0'
compile('id.zelory:compressor:2.1.0') {
exclude group: 'io.reactivex.rxjava2', module: 'rxjava'
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,6 @@
import com.renyu.commonlibrary.basefrag.BaseFragment;
import com.renyu.commonlibrary.params.InitParams;
import com.renyu.imagelibrary.R;
import com.renyu.imagelibrary.params.CommonParams;

import java.io.File;
import java.io.FileNotFoundException;
Expand Down
2 changes: 1 addition & 1 deletion app/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
android:roundIcon="@mipmap/ic_launcher_round"
android:supportsRtl="true"
android:theme="@style/AppTheme">
<activity android:name=".UploadActivity">
<activity android:name=".MainActivity">
<intent-filter>
<action android:name="android.intent.action.MAIN" />

Expand Down
60 changes: 41 additions & 19 deletions app/src/main/java/com/renyu/androidimagelibrary/MainActivity.java
Original file line number Diff line number Diff line change
@@ -1,13 +1,17 @@
package com.renyu.androidimagelibrary;

import android.content.Intent;
import android.graphics.Bitmap;
import android.os.Bundle;
import android.support.v7.app.AppCompatActivity;

import com.facebook.drawee.backends.pipeline.Fresco;
import com.renyu.imagelibrary.preview.ImagePreviewActivity;
import com.renyu.commonlibrary.params.InitParams;
import com.renyu.imagelibrary.commonutils.Utils;

import java.util.ArrayList;
import java.io.File;
import java.io.IOException;

import id.zelory.compressor.Compressor;

public class MainActivity extends AppCompatActivity {

Expand All @@ -16,23 +20,41 @@ protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);

com.blankj.utilcode.util.Utils.init(getApplication());
Fresco.initialize(this);

ArrayList<String> strings=new ArrayList<>();
strings.add("http://7b1g8u.com1.z0.glb.clouddn.com/ccc.jpg");
strings.add("http://img.sj33.cn/uploads/allimg/201302/1-130201105055.jpg");
Intent intent=new Intent(this, ImagePreviewActivity.class);
Bundle bundle=new Bundle();
bundle.putBoolean("canDownload", false);
bundle.putInt("position", 0);
bundle.putBoolean("canEdit", false);
bundle.putStringArrayList("urls", strings);
bundle.putString("rightNav", "查看");
bundle.putParcelable("rightNavClick", new RightNavClick());
intent.putExtras(bundle);
startActivity(intent);
Utils.takePicture(this, 100);

// ArrayList<String> strings=new ArrayList<>();
// strings.add("http://7b1g8u.com1.z0.glb.clouddn.com/ccc.jpg");
// strings.add("http://img.sj33.cn/uploads/allimg/201302/1-130201105055.jpg");
// Intent intent=new Intent(this, ImagePreviewActivity.class);
// Bundle bundle=new Bundle();
// bundle.putBoolean("canDownload", false);
// bundle.putInt("position", 0);
// bundle.putBoolean("canEdit", false);
// bundle.putStringArrayList("urls", strings);
// bundle.putString("rightNav", "查看");
// bundle.putParcelable("rightNavClick", new RightNavClick());
// intent.putExtras(bundle);
// startActivity(intent);

// Utils.showLongPreview(this, "http://7b1g8u.com1.z0.glb.clouddn.com/ccc.jpg", Environment.getExternalStorageDirectory().getPath());
}

@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
super.onActivityResult(requestCode, resultCode, data);
if (requestCode == 100 && resultCode == RESULT_OK) {
File cropFile = null;
try {
cropFile = new Compressor(getApplicationContext())
.setMaxWidth(480)
.setMaxHeight(800)
.setQuality(80)
.setCompressFormat(Bitmap.CompressFormat.JPEG)
.setDestinationDirectoryPath(InitParams.CACHE_PATH)
.compressToFile(new File(data.getExtras().getString("path")));
} catch (IOException e) {
e.printStackTrace();
}
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,7 @@ class UploadActivity: BaseActivity() {
filePaths.add(temp[i])
}
}
if (filePaths==null) {
if (filePaths.size == 0) {
return
}
grid_pic.removeView(grid_pic.getChildAt(grid_pic.childCount -1))
Expand Down
2 changes: 1 addition & 1 deletion build.gradle
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
// Top-level build file where you can add configuration options common to all sub-projects/modules.

buildscript {
ext.kotlin_version = '1.2.0'
ext.kotlin_version = '1.2.10'
repositories {
google()
jcenter()
Expand Down

0 comments on commit 17f328e

Please sign in to comment.