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

相关推荐
2501_937189234 小时前
2025 优化版神马影视 8.8 源码系统|零基础部署
android·源码·开源软件·源代码管理·机顶盒
モンキー・D・小菜鸡儿6 小时前
Android Jetpack Compose 基础控件介绍
android·kotlin·android jetpack·compose
无风之翼7 小时前
android15 休眠唤醒过程中有时候屏幕显示时间一闪而过
android·锁屏
侠***I8 小时前
基于OOA-TCN-BiGRU-Attention的鱼鹰算法优化多变量时间序列预测
kotlin
方白羽9 小时前
Android全局悬浮拖拽视图
android·app·客户端
Jerry10 小时前
Compose 高级状态和附带效应
android
2501_9160074711 小时前
苹果手机iOS应用管理全指南与隐藏功能详解
android·ios·智能手机·小程序·uni-app·iphone·webview
LFly_ice11 小时前
Nest-管道
android·java·数据库
ab_dg_dp13 小时前
android bugreport 模块源码分析
android
2501_9151063214 小时前
全面理解 iOS 帧率,构建从渲染到系统行为的多工具协同流畅度分析体系
android·ios·小程序·https·uni-app·iphone·webview