minor fix
This commit is contained in:
parent
a4c6a82b4f
commit
e8b46b02d8
1 changed files with 15 additions and 13 deletions
|
@ -19,22 +19,24 @@ class TiffRegionFetcher internal constructor(
|
||||||
result: MethodChannel.Result,
|
result: MethodChannel.Result,
|
||||||
) {
|
) {
|
||||||
try {
|
try {
|
||||||
@Suppress("BlockingMethodInNonBlockingContext")
|
val pfd = context.contentResolver.openFileDescriptor(uri, "r")
|
||||||
val fd = context.contentResolver.openFileDescriptor(uri, "r")?.detachFd()
|
if (pfd == null) {
|
||||||
if (fd == null) {
|
|
||||||
result.error("getRegion-tiff-fd", "failed to get file descriptor for uri=$uri", null)
|
result.error("getRegion-tiff-fd", "failed to get file descriptor for uri=$uri", null)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
val options = TiffBitmapFactory.Options().apply {
|
pfd.use {
|
||||||
inDirectoryNumber = page
|
val fd = pfd.detachFd()
|
||||||
inSampleSize = sampleSize
|
val options = TiffBitmapFactory.Options().apply {
|
||||||
inDecodeArea = DecodeArea(regionRect.left, regionRect.top, regionRect.width(), regionRect.height())
|
inDirectoryNumber = page
|
||||||
}
|
inSampleSize = sampleSize
|
||||||
val bitmap = TiffBitmapFactory.decodeFileDescriptor(fd, options)
|
inDecodeArea = DecodeArea(regionRect.left, regionRect.top, regionRect.width(), regionRect.height())
|
||||||
if (bitmap != null) {
|
}
|
||||||
result.success(bitmap.getBytes(canHaveAlpha = true, recycle = true))
|
val bitmap = TiffBitmapFactory.decodeFileDescriptor(fd, options)
|
||||||
} else {
|
if (bitmap != null) {
|
||||||
result.error("getRegion-tiff-null", "failed to decode region for uri=$uri page=$page regionRect=$regionRect", null)
|
result.success(bitmap.getBytes(canHaveAlpha = true, recycle = true))
|
||||||
|
} else {
|
||||||
|
result.error("getRegion-tiff-null", "failed to decode region for uri=$uri page=$page regionRect=$regionRect", null)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
} catch (e: Exception) {
|
} catch (e: Exception) {
|
||||||
result.error("getRegion-tiff-read-exception", "failed to read from uri=$uri page=$page regionRect=$regionRect", e.message)
|
result.error("getRegion-tiff-read-exception", "failed to read from uri=$uri page=$page regionRect=$regionRect", e.message)
|
||||||
|
|
Loading…
Reference in a new issue