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);

效果:

解决问题

相关推荐
weiggle6 分钟前
第八篇:ViewModel + Compose——生产级状态管理实践
android
恋猫de小郭5 小时前
Amper 正式转正 Kotlin Toolchain ,Gradle 未来何去何从
android·前端·flutter
plainGeekDev6 小时前
ButterKnife → ViewBinding
android·java·kotlin
成都大菠萝20 小时前
Android Car CarProperty 车辆信号链路
android
敲代码的鱼20 小时前
PDF 预览与签名批注写回 支持安卓 iOS 鸿蒙 UTS插件
android·前端·ios
时光足迹1 天前
uni-app 视频通话实战:康复师与患者视频问诊的 6 个致命 Bug 与解决方案
android·ios·uni-app
Coffeeee1 天前
闲聊几句,Android老哥们,你们多久没做技改需求了
android·程序员·代码规范
萝卜er1 天前
Fragment 生命周期与状态恢复-《Android深水区(四)》
android
萝卜er1 天前
Intent 显式、隐式与 PendingIntent-《Android深水区(五)》
android
Kapaseker1 天前
一文吃透 Kotlin 集合操作符
android·kotlin