android - 将 ImageView 转换为具有本机分辨率的位图
问题描述
我有以下问题:我imageView
的转换为 a bitmap
,将位图保存到我的画廊时,我可以清楚地看到位图的分辨率/格式与 imageView 相同。但我想获得未裁剪的分辨率。
是否可以将 imageView 转换为具有本机分辨率的位图?
我想将 imageView 转换为位图,而不是通过图像源(URL)创建新的位图,因为我需要实现一个新的异步...
当前转换代码:
BitmapDrawable bitmapDrawable = (BitmapDrawable) imageView.getDrawable();
Bitmap bitmap = bitmapDrawable.getBitmap();
澄清:
网站上的图像具有分辨率800*800px
,而我的 imageView 具有分辨率300*300dp
(更小),我想要源的 res..这可能吗?
解决方案
只需使用 Glide 来加载带有自定义目标的图像。
Glide.with(context) //or view
.asBitmap()
.load(imagePath)
.into(object : CustomTarget<Bitmap>(){
override fun onResourceReady(resource: Bitmap, transition: Transition<in Bitmap>?) {
// do whatever you want with the 'resource' Bitmap
}
override fun onLoadCleared(placeholder: Drawable?) {
// this is called when imageView is cleared on lifecycle so you can recycle your bitmap
}
})
推荐阅读
- dart - 如何在 VSCode 中移动 dart 文件并保持导入正确
- java - WSO2SP 抛出 java.lang.OutOfMemoryError
- angular - RoutingModuleModule 未定义
- django - Django:使用外键查询
- c# - Web Api 在运行时返回状态码 500
- c# - 使用不同的应用程序键运行单元测试用例
- c++ - std::vector 距离函数怎么能给出比 .size() 更高的值?
- c# - 关于 lambda 表达式 C# 的困惑
- c++ - 用于比较正在运行但给出错误结果的数组的简单程序
- python - 根据语句过滤、检查和处理pandas df