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

相关推荐
芦半山34 分钟前
2025:生活是个缓慢受锤的过程
android·年终总结
Kapaseker9 小时前
你不看会后悔的2025年终总结
android·kotlin
alexhilton12 小时前
务实的模块化:连接模块(wiring modules)的妙用
android·kotlin·android jetpack
ji_shuke12 小时前
opencv-mobile 和 ncnn-android 环境配置
android·前端·javascript·人工智能·opencv
sunnyday042614 小时前
Spring Boot 项目中使用 Dynamic Datasource 实现多数据源管理
android·spring boot·后端
幽络源小助理15 小时前
下载安装AndroidStudio配置Gradle运行第一个kotlin程序
android·开发语言·kotlin
inBuilder低代码平台16 小时前
浅谈安卓Webview从初级到高级应用
android·java·webview
豌豆学姐16 小时前
Sora2 短剧视频创作中如何保持人物一致性?角色创建接口教程
android·java·aigc·php·音视频·uniapp
白熊小北极16 小时前
Android Jetpack Compose折叠屏感知与适配
android
HelloBan16 小时前
setHintTextColor不生效
android