Android Drawable转BitmapDrawable再提取Bitmap,Kotlin

Android Drawable转BitmapDrawable再提取Bitmap,Kotlin

XML 复制代码
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:orientation="vertical">

    <ImageView
        android:id="@+id/img1"
        android:layout_width="match_parent"
        android:layout_height="100dp"
        android:scaleType="centerInside" />

    <ImageView
        android:id="@+id/img2"
        android:layout_width="match_parent"
        android:layout_height="100dp"
        android:scaleType="centerInside" />

</LinearLayout>
Kotlin 复制代码
        setContentView(R.layout.two_image)

        val img1 = findViewById<ImageView>(R.id.img1)
        img1.setImageResource(android.R.drawable.ic_dialog_alert)
        val drawable = img1.drawable
        val bitmapDrawable = drawable as? BitmapDrawable
        val bmp = bitmapDrawable?.bitmap

        val img2 = findViewById<ImageView>(R.id.img2)
        img2.setImageBitmap(bmp)

Android Drawable 转化成 Bitmap_zhangphil的博客-CSDN博客/*Java代码 将Drawable转化为Bitmap */ Bitmap drawableToBitmap(Drawable drawable) { int width = drawable.getIntrinsicWidth(); int height = drawable.getIntrinsicHeight(); Bitmap bitmaphttps://blog.csdn.net/zhangphil/article/details/43767535Android传递Bitmap的两种简单方式及其缺陷_android上传bitmap_zhangphil的博客-CSDN博客Android传递Bitmap的几种简单方式一,通过Intent的Bundle。比如有两个activity,A,B,从A进入B。先在A中将Bitmap写进去:Resources res=getResources();Bitmap bmp=BitmapFactory.decodeResource(res, R.drawable.ic_launcher);Bundle b_android上传bitmaphttps://blog.csdn.net/zhangphil/article/details/51655973

相关推荐
年小个大13 小时前
受 go-zero 启发,我给 Flutter 写了一套 CLI 脚手架
android·flutter·架构
Android-Flutter14 小时前
为什么说ActivityThread是主线程?
android·kotlin
余额瞒着我当琳16 小时前
C++模板初阶与STL初探
android·java·c++
知行合一。。。18 小时前
DeepAgents--01--Agent和OpenClaw的相关概念
android·数据库
汪海游龙20 小时前
告别 Play Console 手动上传:从模拟器截图到自动发版的完整流水线
android·ci/cd·github
weixin_4407841120 小时前
【IntentSeivice实现原理】
android·java·开发语言·intentservice
delta_hell20 小时前
【阅读源码--Android】动画之ValueAnimator--2
android·源码·valueanimator
delta_hell20 小时前
【阅读源码--Android】动画之辅助类
android·源码·animator
学习使我健康20 小时前
一个基于 **Jetpack Compose + Material 3** 的 Android 入门示例项目,演示 Compose 声明式 UI 的核心用法
ui·kotlin·android jetpack
delta_hell1 天前
【阅读源码--Android】动画之ValueAnimator--1
android·源码·valueanimator