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

效果:

解决问题

相关推荐
YaBingSec34 分钟前
玄机靶场-2024ccb初赛sc05 WP
android·运维·网络·笔记·安全·ssh
常利兵42 分钟前
解锁Android嵌入式照片选择器,让你的App体验丝滑起飞
android
峥嵘life1 小时前
Android 切换用户后无法获取 MAC 地址分析解决
android·python·macos
JJay.1 小时前
Android BLE 为什么连上了却收不到数据
android
歪楼小能手1 小时前
Android16在开机向导最后添加一个声明界面
android·java·平板
夏沫琅琊1 小时前
Android联系人导入导出
android·kotlin
zh_xuan1 小时前
把Android Library 上传到github并在工程中引用该远程仓库
android·github·远程仓库
诸神黄昏EX1 小时前
Android Google MADA
android
盖丽男1 小时前
使用 GitHub Actions 自动打包 Android APK
android·github
小林望北1 小时前
Kotlin 协程:StateFlow 与 SharedFlow 深度解析
android·开发语言·kotlin