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

效果:

解决问题

相关推荐
kymjs张涛5 分钟前
OpenClaw 学习小组:初识
android·linux·人工智能
范特西林4 小时前
实战演练——从零实现一个高性能 Binder 服务
android
范特西林4 小时前
代码的生成:AIDL 编译器与 Parcel 的序列化艺术
android
范特西林4 小时前
深入内核:Binder 驱动的内存管理与事务调度
android
范特西林5 小时前
解剖麻雀:Binder 通信的整体架构全景图
android
范特西林5 小时前
破冰之旅:为什么 Android 选择了 Binder?
android
奔跑中的蜗牛6666 小时前
一次播放器架构升级:Android 直播间 ANR 下降 60%
android
测试工坊9 小时前
Android 视频播放卡顿检测——帧率之外的第二战场
android
Kapaseker10 小时前
一杯美式深入理解 data class
android·kotlin
鹏多多10 小时前
Flutter使用screenshot进行截屏和截长图以及分享保存的全流程指南
android·前端·flutter