下面列出了android.os.MemoryFile#close ( ) 实例代码,或者点击链接到github查看源代码,也可以在右侧发表评论。
private Bitmap decodeFileDescriptorAsPurgeable(
CloseableReference<PooledByteBuffer> bytesRef,
int inputLength,
byte[] suffix,
BitmapFactory.Options options) {
MemoryFile memoryFile = null;
try {
memoryFile = copyToMemoryFile(bytesRef, inputLength, suffix);
FileDescriptor fd = getMemoryFileDescriptor(memoryFile);
if (mWebpBitmapFactory != null) {
Bitmap bitmap = mWebpBitmapFactory.decodeFileDescriptor(fd, null, options);
return Preconditions.checkNotNull(bitmap, "BitmapFactory returned null");
} else {
throw new IllegalStateException("WebpBitmapFactory is null");
}
} catch (IOException e) {
throw Throwables.propagate(e);
} finally {
if (memoryFile != null) {
memoryFile.close();
}
}
}
@Test
public void test_webp_extended_decoding_filedescriptor_bitmap() throws Throwable {
final MemoryFile memoryFile = getMemoryFile("webp_e.webp");
final Bitmap bitmap =
mWebpBitmapFactory.decodeFileDescriptor(getMemoryFileDescriptor(memoryFile), null, null);
memoryFile.close();
assertBitmap(bitmap, 480, 320);
}
@Test
public void test_webp_extended_with_alpha_decoding_filedescriptor_bitmap() throws Throwable {
final MemoryFile memoryFile = getMemoryFile("webp_ea.webp");
final Bitmap bitmap =
mWebpBitmapFactory.decodeFileDescriptor(getMemoryFileDescriptor(memoryFile), null, null);
memoryFile.close();
assertBitmap(bitmap, 400, 301);
}
@Test
public void test_webp_lossless_decoding_filedescriptor_bitmap() throws Throwable {
final MemoryFile memoryFile = getMemoryFile("webp_ll.webp");
final Bitmap bitmap =
mWebpBitmapFactory.decodeFileDescriptor(getMemoryFileDescriptor(memoryFile), null, null);
memoryFile.close();
assertBitmap(bitmap, 400, 301);
}
@Test
public void test_webp_plain_decoding_filedescriptor_bitmap() throws Throwable {
final MemoryFile memoryFile = getMemoryFile("webp_plain.webp");
final Bitmap bitmap =
mWebpBitmapFactory.decodeFileDescriptor(getMemoryFileDescriptor(memoryFile), null, null);
memoryFile.close();
assertBitmap(bitmap, 320, 214);
}
public static void safeClose(MemoryFile mf) {
if (mf != null) {
mf.close();
}
}