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

效果:

解决问题

相关推荐
赏金术士16 小时前
Retrofit + Kotlin 协程(Android 实战教程)
android·kotlin·retrofit
大炮筒1 天前
COCOS2DX4.0CPPWIN移植安卓踩坑总结
android
qq_422828621 天前
android图形学之SurfaceControl和Surface的关系 五
android·开发语言·python
tongyiixiaohuang1 天前
轻易云平台助力快麦数据入库MySQL
android·数据库·mysql
JohnnyDeng941 天前
Android 包体积优化:R8/ProGuard 深度配置
android
qq_452396231 天前
第六篇:《JMeter逻辑控制器:循环、条件和交替执行》
android·java·jmeter
cwzqf1 天前
Jectpack Compose项目组件代码分享(1):分页加载组件
android
@北海怪兽1 天前
SQL常见函数整理 _ STRING_AGG()
android·数据库·sql
鹏晨互联1 天前
【Compose vs XML:边框内外间距的实现对比】
android·xml
Android系统攻城狮1 天前
Android tinyalsa深度解析之pcm_plugin_write调用流程与实战(一百七十九)
android·pcm·tinyalsa·android16·音频进阶·android音频进阶