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

相关推荐
awu的Android笔记15 分钟前
网络闪断 + DNS 故障:Android弱网模拟中最容易被忽视的两个场景
android·tcp/ip
Flynt34 分钟前
Android 17内存限制:我是怎么发现App被系统悄悄干掉的
android·性能优化
消失的旧时光-19431 小时前
Kotlin 协程设计思想(七):为什么 Kotlin 要设计 SupervisorJob 和 supervisorScope?
android·开发语言·kotlin
故渊at2 小时前
第一板块:Android 系统基石与运行原理 | 第五篇:Context 上下文与资源配置体系
android·人工智能·opencv·context·上下文·资源配置体系
故渊at2 小时前
第一板块:Android 系统基石与运行原理 | 第四篇:进程孵化(Zygote)与 Low Memory Killer 机制
android·虚拟机·zygote·系统启动·low memory·进程孵化
JohnnyDeng942 小时前
【Android】RecyclerView性能优化与缓存机制:从卡顿到丝滑的完整指南
android·性能优化·kotlin·mvvm
zfoo-framework2 小时前
kotlin中体会到一些比较好用的点
android·开发语言·kotlin
我是唐青枫2 小时前
Kotlin also 详解:附加操作、链式调试与实战示例
kotlin
●VON4 小时前
AtomGit Flutter鸿蒙客户端:文件树与代码浏览
android·服务器·安全·flutter·harmonyos·鸿蒙
故渊at11 小时前
系列三:组件化与模块化进阶 | 第11篇 组件化项目规范与问题根治:依赖、资源、Manifest 与混淆的全链路管控
android·架构·mvvm·模块化·组件化