我正在尝试从 SimpleDraweeView 获取位图。
我已经使用 uri 图像设置了 SimpleDraweeView:
final Uri uri = new Uri.Builder()
.scheme(UriUtil.LOCAL_RESOURCE_SCHEME)
.path(returnUri.getPath())
.build();
profileImage.setImageURI(returnUri);
现在我试图将图像保存在手机的内存(存储)中。
Bitmap b = ((BitmapDrawable) profileImage.getDrawable()).getBitmap(); // ImageDiskHelper.drawableToBitmap(profileImage.getDrawable().get);
try {
ImageDiskHelper.saveToInternalStorage(b, "MyActualProfileImage");
} catch(Exception c){ }
但是如果我使用上面的代码,我会得到: com.facebook.drawee.generic.RootDrawable 无法转换为 android.graphics.drawable.BitmapDrawable
我将 profileImage.getDrawable 转换为位图,图像如下:空图像 https://i.stack.imgur.com/vbDrk.png
我正在尝试获取 SimpleDraweeView 显示的位图
让位图可绘制并不是一个好主意,因为 Fresco 的底层实现将来可能会发生变化,这会破坏您的代码。
我猜你真的只想要原始编码的图像字节(这样你就不必重新编码图像)。
您可以使用以下命令获取编码图像字节
DataSource<CloseableReference<PooledByteBuffer>>
dataSource = imagePipeline.fetchEncodedImage(imageRequest, callerContext);
由于您之前已经获取了图像,因此它应该立即可用,您可以执行类似的操作
try {
CloseableReference<PooledByteBuffer> encodedImage = dataSource.getResult();
if (imageReference != null) {
try {
// Do something with the encoded image, but do not keep the reference to it!
// The image may get recycled as soon as the reference gets closed below.
} finally {
CloseableReference.closeSafely(encodedImage);
}
} else {
// cache miss
...
}
} finally {
dataSource.close();
}
不要忘记关闭引用,以免泄漏内存。
您可以找到更多信息here http://frescolib.org/docs/using-image-pipeline.html.
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)