【发布时间】:2020-02-28 11:19:32
【问题描述】:
在我的 Android - Kotlin 应用程序中,我试图从图像中获取位图以使用它的colorPallete,这是我的XML 文件中的ImageView:
<ImageView
android:id="@+id/dressImage_1"
android:layout_width="142dp"
android:layout_height="123dp"
android:contentDescription="@string/app_name"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent"
app:srcCompat="@drawable/icon" />
这是我添加图片的方法:
Picasso.get().load(dress.image1).into(mDressImage1)
到这里一切顺利。
注意:dress.image1返回一个网址
在此之后,当我尝试以这种方式从imageView 获取bitmap 时:
val bitmap = (mDressImage1?.drawable as BitmapDrawable).bitmap
它只是崩溃了。 logcat 什么都没有
更新
它给了我错误null cannot be cast to non-null type android.graphics.drawable.BitmapDrawable
指向val bitmap = (mDressImage1?.drawable as BitmapDrawable).bitmap这一行
【问题讨论】:
-
也许这会有所帮助:查看 BitmapFactory.decodeResource developer.android.com/reference/android/graphics/…
标签: android kotlin picasso android-bitmap