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

效果:

解决问题

相关推荐
CS_Zero6 分钟前
安卓开发:Linux的android工具命令
android·linux·运维
fellow9931 分钟前
DSH Desktop - Android Edition
android·agent·deepseek·harness·dsh
Carson带你学Android36 分钟前
Android Studio Rabbit 2 发布:除了Gemini,40+ AI Agent 正式入驻!
android·ai编程
三少爷的鞋13 小时前
Java 线程自上而下,Kotlin 协程自下而上
android
好的佩奇15 小时前
Dart 之增强枚举
android·flutter·dart
梦影_15 小时前
MySQL进阶教程(五)—— SQL调优(下)
android·大数据·数据库·后端·sql·mysql·database
好的佩奇18 小时前
蓝牙之无线电与通信距离
android·flutter·蓝牙
vilya18 小时前
我把一套完整的 Python Agent 运行时塞进手机 APK:依赖闭包、Rust 轮子和三个真机坑
android
呆呆敲代码的小Y20 小时前
【实战精选面试题】C# 面试题详细解答,按难易程度排序
android·java·游戏·c#·游戏开发·unity面试题·c#面试题
思想觉悟21 小时前
SEAndroid实战
android·linux·c++