@@ -31,30 +31,24 @@ object ImageConvert {
31
31
imageFile.createNewFile()
32
32
33
33
FileOutputStream (imageFile).use { fos ->
34
- if (external) {
35
- BitmapFactory .decodeStream(URL (photoUri).openStream()).apply {
36
- if (Build .VERSION .SDK_INT >= 30 ) {
37
- compress(Bitmap .CompressFormat .WEBP_LOSSY , COMPRESS_QUALITY , fos)
38
- } else {
39
- compress(Bitmap .CompressFormat .JPEG , COMPRESS_QUALITY , fos)
40
- }
41
-
42
- recycle()
34
+ val bitmapFactory =
35
+ if (external) {
36
+ BitmapFactory .decodeStream(URL (photoUri).openStream())
37
+ } else {
38
+ val bufferedInputStream = BufferedInputStream (
39
+ context.contentResolver.openInputStream(photoUri.toUri())
40
+ )
41
+ BitmapFactory .decodeStream(bufferedInputStream)
43
42
}
44
- } else {
45
- val bufferedInputStream = BufferedInputStream (
46
- context.contentResolver.openInputStream(photoUri.toUri())
47
- )
48
43
49
- BitmapFactory .decodeStream(bufferedInputStream) .apply {
50
- if (Build .VERSION .SDK_INT >= 30 ) {
51
- compress(Bitmap .CompressFormat .WEBP_LOSSY , COMPRESS_QUALITY , fos)
52
- } else {
53
- compress(Bitmap .CompressFormat .JPEG , COMPRESS_QUALITY , fos)
54
- }
44
+ bitmapFactory .apply {
45
+ if (Build .VERSION .SDK_INT >= 30 ) {
46
+ compress(Bitmap .CompressFormat .WEBP_LOSSY , COMPRESS_QUALITY , fos)
47
+ } else {
48
+ compress(Bitmap .CompressFormat .JPEG , COMPRESS_QUALITY , fos)
49
+ }
55
50
56
- recycle()
57
- } ? : throw NullPointerException ()
51
+ recycle()
58
52
}
59
53
60
54
fos.flush()
0 commit comments