|
|
|
@ -362,32 +362,40 @@ public class InfoFragment extends BaseFragment { |
|
|
|
|
if (picFile.createNewFile()) { |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Bitmap bitmap; |
|
|
|
|
Bitmap srcbitmap; |
|
|
|
|
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.P) { |
|
|
|
|
bitmap = ImageDecoder.decodeBitmap(ImageDecoder.createSource(requireContext().getContentResolver(), uri)); |
|
|
|
|
srcbitmap = ImageDecoder.decodeBitmap(ImageDecoder.createSource(requireContext().getContentResolver(), uri)); |
|
|
|
|
|
|
|
|
|
} else { |
|
|
|
|
bitmap = MediaStore.Images.Media.getBitmap(requireContext().getContentResolver(), uri); |
|
|
|
|
srcbitmap = MediaStore.Images.Media.getBitmap(requireContext().getContentResolver(), uri); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
Context context = requireContext(); |
|
|
|
|
TextView textView = new TextView(getContext()); |
|
|
|
|
|
|
|
|
|
TextView textView = new TextView(context); |
|
|
|
|
textView.setTextSize(18); |
|
|
|
|
textView.setGravity(Gravity.CENTER | Gravity.CENTER_HORIZONTAL | Gravity.CENTER_VERTICAL); |
|
|
|
|
textView.setText(R.string.compress_img); |
|
|
|
|
textView.setText(R.string.scale_img); |
|
|
|
|
|
|
|
|
|
AlertDialog uploadDialog = new AlertDialog.Builder(context) |
|
|
|
|
.setView(textView).setCancelable(false).show(); |
|
|
|
|
|
|
|
|
|
//缩放图片
|
|
|
|
|
int size = getResources().getInteger(R.integer.photo_size); |
|
|
|
|
Bitmap scalebitmap = Bitmap.createScaledBitmap(srcbitmap, size, size, true); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
compressHandler = new Handler(Looper.getMainLooper()) { |
|
|
|
|
@Override |
|
|
|
|
public void handleMessage(@NonNull Message msg) { |
|
|
|
|
if (msg.what == Response.Result.OK.ordinal()) { |
|
|
|
|
Log.i(InfoFragment.class.getName(), "位图大小:" + bitmap.getByteCount() / 1024 + "KB" + ",压缩大小" + picFile.length() / 1024 + "KB"); |
|
|
|
|
Log.i(InfoFragment.class.getName(), "原图大小:" + srcbitmap.getByteCount() / 1024 / 1024F + "MB,缩放大小:" + scalebitmap.getByteCount() / 1024 / 1024F + "MB,压缩大小:" + picFile.length() / 1024 / 1024F + "MB"); |
|
|
|
|
uploadImgHandler = new Handler(Looper.getMainLooper()) { |
|
|
|
|
@Override |
|
|
|
|
public void handleMessage(@NonNull Message msg) { |
|
|
|
|
uploadDialog.dismiss(); |
|
|
|
|
if (msg.what == Response.Result.OK.ordinal()) { |
|
|
|
|
headimg.setImageBitmap(bitmap); |
|
|
|
|
headimg.setImageBitmap(scalebitmap); |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
}; |
|
|
|
@ -400,9 +408,10 @@ public class InfoFragment extends BaseFragment { |
|
|
|
|
} |
|
|
|
|
}; |
|
|
|
|
|
|
|
|
|
textView.setText(R.string.compress_img); |
|
|
|
|
new Thread(() -> { |
|
|
|
|
try { |
|
|
|
|
bitmap.compress(Bitmap.CompressFormat.PNG, getResources().getInteger(R.integer.photo_quality), new FileOutputStream( |
|
|
|
|
scalebitmap.compress(Bitmap.CompressFormat.PNG, getResources().getInteger(R.integer.photo_quality), new FileOutputStream( |
|
|
|
|
picFile)); |
|
|
|
|
compressHandler.sendEmptyMessage(Response.Result.OK.ordinal()); |
|
|
|
|
} catch (FileNotFoundException e) { |
|
|
|
|