Skip to content

Instantly share code, notes, and snippets.

View m-kikuchi777's full-sized avatar
👻
Working in office.

m-kikuchi777 m-kikuchi777

👻
Working in office.
  • Tokyo, Japan
View GitHub Profile
@m-kikuchi777
m-kikuchi777 / ClipSamplePainter.dart
Last active November 20, 2023 14:16
ClipSamplePainter
import 'dart:ui';
import 'package:flutter/material.dart';
void main() => runApp(MyApp());
class MyApp extends StatelessWidget {
@override
Widget build(BuildContext context) {
return MaterialApp(
@m-kikuchi777
m-kikuchi777 / ScopedStorageFileSize.kt
Created December 19, 2019 03:19
Scoped Storage Read of FileSize
contentResolver.openFileDescriptor(fileUri, "r")?.use {
it.statSize
} ?: throw IOException("Could not get file size")
@m-kikuchi777
m-kikuchi777 / ScopedStorageFileDescriptor.kt
Last active December 19, 2019 05:12
Scoped Storage Read with BitmapFactory.Options
val bitmapFactoryOptions = BitmapFactory.Options()
bitmapFactoryOptions.inSampleSize = sampleSize
var bitmap = contentResolver.openFileDescriptor(path, "r")?.use {
BitmapFactory.decodeFileDescriptor(it.fileDescriptor, null, bitmapFactoryOptions)
} ?: return null
@m-kikuchi777
m-kikuchi777 / ScopedStorageWriteBitmap.kt
Created December 18, 2019 13:25
Scoped Storage Write of Bitmap
context.contentResolver.openOutputStream(imageUri).use { out ->
bmp.compress(Bitmap.CompressFormat.JPEG, 90, out)
}
@m-kikuchi777
m-kikuchi777 / ScopedStorageReadBitmap.kt
Last active December 19, 2019 04:39
Scoped Storage Read as Bitmap
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.Q) {
ImageDecoder.decodeBitmap(ImageDecoder.createSource(contentResolver, uri))
} else {
contentResolver.openInputStream(uri)?.use { inputStream ->
BitmapFactory.decodeStream(inputStream)
}
}
@m-kikuchi777
m-kikuchi777 / ScopedStorageWrite.kt
Last active December 19, 2019 05:11
Scoped Storage Write
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) {
@m-kikuchi777
m-kikuchi777 / ScopedStorageRead.kt
Last active December 18, 2019 12:57
Scoped Storage - Read
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
)