This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import 'dart:ui'; | |
import 'package:flutter/material.dart'; | |
void main() => runApp(MyApp()); | |
class MyApp extends StatelessWidget { | |
@override | |
Widget build(BuildContext context) { | |
return MaterialApp( |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
contentResolver.openFileDescriptor(fileUri, "r")?.use { | |
it.statSize | |
} ?: throw IOException("Could not get file size") |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
val bitmapFactoryOptions = BitmapFactory.Options() | |
bitmapFactoryOptions.inSampleSize = sampleSize | |
var bitmap = contentResolver.openFileDescriptor(path, "r")?.use { | |
BitmapFactory.decodeFileDescriptor(it.fileDescriptor, null, bitmapFactoryOptions) | |
} ?: return null |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
context.contentResolver.openOutputStream(imageUri).use { out -> | |
bmp.compress(Bitmap.CompressFormat.JPEG, 90, out) | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.Q) { | |
ImageDecoder.decodeBitmap(ImageDecoder.createSource(contentResolver, uri)) | |
} else { | |
contentResolver.openInputStream(uri)?.use { inputStream -> | |
BitmapFactory.decodeStream(inputStream) | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
val values = ContentValues().apply { | |
put(MediaStore.Images.Media.DISPLAY_NAME,"${System.currentTimeMillis()}") | |
put(MediaStore.Images.Media.MIME_TYPE, "image/jpeg") | |
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.Q) { | |
put(MediaStore.Images.Media.RELATIVE_PATH, "Picture/sample") | |
put(MediaStore.Images.Media.IS_PENDING, true) | |
} | |
} | |
val externalStorageUri = if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.Q) { |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
val targetUri = if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.Q) { | |
MediaStore.Images.Media.getContentUri(MediaStore.VOLUME_EXTERNAL_PRIMARY) | |
} else { | |
MediaStore.Images.Media.EXTERNAL_CONTENT_URI | |
} | |
val projection: Array<String> = arrayOf( | |
MediaStore.Images.Media._ID | |
) |