Skip to content

Commit

Permalink
提供设置文件名方法
Browse files Browse the repository at this point in the history
  • Loading branch information
nanchen2251 committed Apr 10, 2017
1 parent cc98537 commit f1590ec
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 3 deletions.
6 changes: 6 additions & 0 deletions .idea/vcs.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
Expand Up @@ -51,12 +51,16 @@ public void compress(View view) {
// 默认的压缩方法,多张图片只需要直接加入循环即可
newFile = CompressHelper.getDefault(this).compressToFile(oldFile);

// 你也可以自定义压缩

// String yourFileName = "123.jpg";
//
// // 你也可以自定义压缩
// newFile = new CompressHelper.Builder(this)
// .setMaxWidth(720) // 默认最大宽度为720
// .setMaxHeight(960) // 默认最大高度为960
// .setQuality(80) // 默认压缩质量为80
// .setCompressFormat(CompressFormat.JPEG) // 设置默认压缩为jpg格式
// .setFileName(yourFileName) // 设置你的文件名
// .setDestinationDirectoryPath(Environment.getExternalStoragePublicDirectory(
// Environment.DIRECTORY_PICTURES).getAbsolutePath())
// .build()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,9 @@ public class CompressHelper {
* 存储路径
*/
private String destinationDirectoryPath;
/**
* 文件名前缀
*/
private String fileNamePrefix;
/**
* 文件名
Expand Down Expand Up @@ -170,6 +173,10 @@ public Builder setDestinationDirectoryPath(String destinationDirectoryPath) {
return this;
}

/**
* 设置文件前缀
* @param prefix 前缀
*/
public Builder setFileNamePrefix(String prefix) {
mCompressHelper.fileNamePrefix = prefix;
return this;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,6 @@ static Bitmap getScaledBitmap(Context context, Uri imageUri, float maxWidth, flo
options.inJustDecodeBounds = true;
Bitmap bmp = BitmapFactory.decodeFile(filePath, options);
if (bmp == null) {

InputStream inputStream = null;
try {
inputStream = new FileInputStream(filePath);
Expand Down Expand Up @@ -112,7 +111,6 @@ static Bitmap getScaledBitmap(Context context, Uri imageUri, float maxWidth, flo
//load the bitmap getTempFile its path
bmp = BitmapFactory.decodeFile(filePath, options);
if (bmp == null) {

InputStream inputStream = null;
try {
inputStream = new FileInputStream(filePath);
Expand Down

0 comments on commit f1590ec

Please sign in to comment.