android - bitmap.sameAs() 不适用于 Intent Picking 的图像比较
问题描述
我的应用程序检查新选择的图像是否与以前的图像相同,这样我就不需要更新云数据,但newBitmap.sameAs(oldBitmap)
即使我选择了同一张照片,也总是返回 false。
我的一段代码:
private lateinit var oldBitmap: Bitmap
private lateinit var newBitmap: Bitmap
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
setContentView(R.layout.activity_my_profile)
myProfilePictureUrl = intent.getStringExtra("myProfilePictureUrl")!!
if (myProfilePictureUrl.isNotEmpty()) {
Picasso.get().load(myProfilePictureUrl).into(my_profile_imageView)
}
oldBitmap = (my_profile_imageView.drawable as BitmapDrawable).bitmap //for later comparison
my_profile_imageView.setOnClickListener {
val intent = Intent(Intent.ACTION_PICK)
intent.type = "image/*"
startActivityForResult(intent, RESULT_CODE_PICK_IMAGE)
}
}
override fun onActivityResult(requestCode: Int, resultCode: Int, data: Intent?) {
super.onActivityResult(requestCode, resultCode, data)
if (requestCode == RESULT_CODE_PICK_IMAGE && resultCode == Activity.RESULT_OK) {
val inputStream = contentResolver.openInputStream(data!!.data!!)
val bitmap = BitmapFactory.decodeStream(inputStream)
newBitmap = bitmap //for comparison
my_profile_imageView.setImageBitmap(bitmap)
}
}
当用户点击操作栏上的“保存”按钮时,它会首先检查它们是否是同一张照片:
private fun updateProfile(nickname: String) {
if (this::newBitmap.isInitialized && !newBitmap.sameAs(oldBitmap)) { //here
//upload task code
}
}
问题是:
!newBitmap.sameAs(oldBitmap)
即使它们是同一张照片,总是返回 false,可能是PICASSO的问题?或者我以前比较的方式不对。任何帮助,将不胜感激。
解决方案
推荐阅读
- javascript - 如何将表格放置在侧边栏旁边的vue中
- javascript - 如何在 onClick 事件反应 js 上从子级渲染其他组件?
- python - 名称未定义 python
- micronaut - 忽略@MicronautTest 的“数据源”
- django - 登录和注销视图是必要的吗?( SimpleJwt+Django 休息框架)
- python - 在 Gtk 4.0 + X11 中列出窗口
- c# - 如何通过主要活动更改媒体播放器的音量
- android - 使用本机反应更改整个系统(移动)字体
- prolog - Prolog回溯位置
- css - 是否可以使边界半径的行为像 figma