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

效果:

解决问题

相关推荐
-SOLO-42 分钟前
解决VMware 显示比例被重置的问题
android
alexhilton1 小时前
探究Android Views、Flutter和Compose如何渲染你的UI
android·kotlin·android jetpack
Lesile4 小时前
Android:Hilt框架入门 · 在ViewUI和ComposeUI下的应用
android·android jetpack
用户423816229074 小时前
Android 16 WebView 页面顶部挖孔/通知栏不能显示UI问题排查
android
weixin_727535625 小时前
Loop 已死,Graph 新生:AI 工作流的范式革命
android·人工智能·rxjava
严同学正在努力6 小时前
从备份到恢复:我用 30 分钟恢复了误删的核心业务表
android·java·数据库·ai
梦想三三6 小时前
LangChain Output Parser 实战:从字符串到结构化数据的完整指南
android·服务器·langchain·github·uv
爱笑鱼9 小时前
Binder(八):远端进程死了,BinderProxy 为什么还能收到通知?
android
Android-Flutter9 小时前
Kotlin 冷流与热流详解
android·kotlin
zhangphil9 小时前
Android ContentProvider/ContentResolver读图片,跨进程 IPC慢
android