Skip to content

Commit 257e7f2

Browse files
author
郑梓斌
committed
fix #272 #267 #262, over.
1 parent de4ba8a commit 257e7f2

File tree

4 files changed

+7
-15
lines changed

4 files changed

+7
-15
lines changed

example/src/main/assets/img_0

803 KB
Binary file not shown.

example/src/main/assets/img_1

-803 KB
Binary file not shown.

example/src/main/java/top/zibin/luban/example/MainActivity.java

+3-2
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@
3737

3838
public class MainActivity extends AppCompatActivity {
3939
private static final String TAG = "Luban";
40+
private static final int range = 3;
4041

4142
private List<ImageBean> mImageList = new ArrayList<>();
4243
private ImageAdapter mAdapter = new ImageAdapter(mImageList);
@@ -93,7 +94,7 @@ public boolean onOptionsItemSelected(MenuItem item) {
9394
private List<File> assetsToFiles() {
9495
final List<File> files = new ArrayList<>();
9596

96-
for (int i = 0; i < 3; i++) {
97+
for (int i = 0; i < range; i++) {
9798
try {
9899
InputStream is = getResources().getAssets().open("img_" + i);
99100
File file = new File(getExternalFilesDir(null), "test_" + i);
@@ -122,7 +123,7 @@ private List<Uri> assetsToUri() {
122123
final List<Uri> uris = new ArrayList<>();
123124
final List<File> files = assetsToFiles();
124125

125-
for (int i = 0; i < 2; i++) {
126+
for (int i = 0; i < range; i++) {
126127
Uri uri = Uri.fromFile(files.get(i));
127128
uris.add(uri);
128129
}

library/src/main/java/top/zibin/luban/Checker.java

+4-13
Original file line numberDiff line numberDiff line change
@@ -157,19 +157,10 @@ && pack(jpeg, offset + 6, 2, false) == 0) {
157157

158158
String extSuffix(InputStreamProvider input) {
159159
try {
160-
Bitmap bitmap = BitmapFactory.decodeStream(input.open(), null, new BitmapFactory.Options());
161-
String suffix = TextUtils.isEmpty(input.getPath()) ? "" :
162-
input.getPath().substring(input.getPath().lastIndexOf("."), input.getPath().length());
163-
164-
if (bitmap.hasAlpha()) {
165-
return PNG;
166-
} else if (TextUtils.isEmpty(suffix)) {
167-
return JPG;
168-
} else if (!format.contains(suffix)) {
169-
return JPG;
170-
}
171-
172-
return suffix;
160+
BitmapFactory.Options options = new BitmapFactory.Options();
161+
options.inJustDecodeBounds = true;
162+
BitmapFactory.decodeStream(input.open(), null, options);
163+
return options.outMimeType.replace("image/", ".");
173164
} catch (Exception e) {
174165
return JPG;
175166
}

0 commit comments

Comments
 (0)