Android 百度地图 bitmap 透明图片背景变黑色

现象:

本来透明背景的png图片渲染出来时黑色的了

原因:

为了节省内存资源对图片进行了压缩,使用到了

复制代码
bitmap.compress(Bitmap.CompressFormat format, int quality, OutputStream stream)方法,具体设置为
复制代码
bitmap.compress(Bitmap.CompressFormat.JPEG, 50, stream);

其中将bitmap设置为了Bitmap.CompressFormat.JPEG格式,JPEG没有透明通道,渲染出来就是默认的黑色,因此需要将格式设置为PNG格式,即:

复制代码
bitmap.compress(Bitmap.CompressFormat.PNG, 50, stream);

效果:

解决问题

相关推荐
撩得Android一次心动12 分钟前
Android Jetpack 概述
android·android jetpack
JinBeen14 分钟前
sourcetree下码云gitee的ssh经常失效问题
android·gitee·ssh
帅得不敢出门1 小时前
Android各芯片平台日志打开及获取
android
极客小云1 小时前
【Android Gradle 构建常见报错及解决方法大全】
android·运维开发
Just_Paranoid2 小时前
【TaskbarDelegate】屏蔽上滑返回桌面手势功能
android·systemui·navigation·launcher·gesture
赛恩斯2 小时前
asfp 如何导入并使用aosp13
android
诸神黄昏EX2 小时前
Android Safety 系列专题【篇三:Secure Boot机制】
android
李坤林3 小时前
Android Binder 详解(4) Binder 线程池
android·java·binder
PuddingSama4 小时前
Gson 很好,但在Kotlin上有更合适的序列化工具「Kotlin Serialization」
android·kotlin·gson
教程分享大师5 小时前
移动云电脑W132D安卓9当贝固件线刷机包_ROM刷机教程
android