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

效果:

解决问题

相关推荐
一笑的小酒馆4 小时前
Android中WebRTC通信
android
KevinWang_6 小时前
Android Hilt 依赖注入
android
古法安卓7 小时前
Android-深入理解 Android 回调(Callback)机制
android·性能优化·android studio
古法安卓7 小时前
Android-车机 GNSS 定位数据接收问题排查
android·java·android studio
FungLeo9 小时前
Flutter 吸顶分组列表实战:语义桶分组 + 点击头平滑滚动
android·flutter
阿巴斯甜9 小时前
Android 自定义权限
android
FungLeo10 小时前
Flutter 超长 StatefulWidget 拆分术:part of + extension on State 实战
android·flutter·dart
小王C语言11 小时前
MySQL 数据类型:数值类型、字符串类型、日期和时间类型、enum 和 set、find_in_set 查询
android·数据库·mysql
我命由我1234511 小时前
Android 控件 - CardView(快速实现圆角)
android·java·java-ee·kotlin·android studio·android-studio·android runtime
码云数智-园园12 小时前
Android 全方位性能优化合集
android·性能优化