Commit 24c17ec 1 parent cfd381e commit 24c17ec Copy full SHA for 24c17ec
File tree 1 file changed +10
-7
lines changed
core/common/src/main/java/io/github/jja08111/core/common/image
1 file changed +10
-7
lines changed Original file line number Diff line number Diff line change @@ -7,19 +7,22 @@ import android.net.Uri
7
7
import android.os.Build
8
8
import android.provider.MediaStore
9
9
import dagger.hilt.android.qualifiers.ApplicationContext
10
+ import kotlinx.coroutines.Dispatchers
11
+ import kotlinx.coroutines.withContext
10
12
import javax.inject.Inject
11
13
import javax.inject.Singleton
12
14
13
15
@Singleton
14
16
class BitmapCreator @Inject constructor(
15
17
@ApplicationContext private val context : Context ,
16
18
) {
17
- fun create (imageUri : Uri ): Bitmap {
18
- return if (Build .VERSION .SDK_INT >= Build .VERSION_CODES .P ) {
19
- ImageDecoder .decodeBitmap(ImageDecoder .createSource(context.contentResolver, imageUri))
20
- } else {
21
- @Suppress(" DEPRECATION" )
22
- MediaStore .Images .Media .getBitmap(context.contentResolver, imageUri)
19
+ suspend fun create (imageUri : Uri ): Bitmap =
20
+ withContext(Dispatchers .IO ) {
21
+ if (Build .VERSION .SDK_INT >= Build .VERSION_CODES .P ) {
22
+ ImageDecoder .decodeBitmap(ImageDecoder .createSource(context.contentResolver, imageUri))
23
+ } else {
24
+ @Suppress(" DEPRECATION" )
25
+ MediaStore .Images .Media .getBitmap(context.contentResolver, imageUri)
26
+ }
23
27
}
24
- }
25
28
}
You can’t perform that action at this time.
0 commit comments