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

相关推荐
一丝晨光2 小时前
Java、PHP、ASP、JSP、Kotlin、.NET、Go
java·kotlin·go·php·.net·jsp·asp
GEEKVIP2 小时前
手机使用技巧:8 个 Android 锁屏移除工具 [解锁 Android]
android·macos·ios·智能手机·电脑·手机·iphone
model20054 小时前
android + tflite 分类APP开发-2
android·分类·tflite
彭于晏6894 小时前
Android广播
android·java·开发语言
与衫5 小时前
掌握嵌套子查询:复杂 SQL 中 * 列的准确表列关系
android·javascript·sql
500了11 小时前
Kotlin基本知识
android·开发语言·kotlin
人工智能的苟富贵12 小时前
Android Debug Bridge(ADB)完全指南
android·adb
小雨cc5566ru17 小时前
uniapp+Android面向网络学习的时间管理工具软件 微信小程序
android·微信小程序·uni-app
bianshaopeng18 小时前
android 原生加载pdf
android·pdf
hhzz18 小时前
Linux Shell编程快速入门以及案例(Linux一键批量启动、停止、重启Jar包Shell脚本)
android·linux·jar