java - 如何从imagebutton获取位图
问题描述
当我ImageButton
点击它时,画廊将出现以选择图像并发送bitmap
回以显示在此ImageButton
。但我必须得到bitmap
这个 ImageButton 上显示的内容,然后将其保存到数据库中byte[]
解决方案
首先bitmap
从ImgaeButton
Bitmap bitmap = ((BitmapDrawable)imageButton.getDrawable()).getBitmap();
然后将其转换bitmap
为byteArray
ByteArrayOutputStream outputStream = new ByteArrayOutputStream();
bitmap.compress(Bitmap.CompressFormat.PNG, 100, outputStream);
byte[] byteArray = outputStream.toByteArray();
推荐阅读
- angular - 如何在延迟加载的模块Angular 10中设置APP_BASE_HREF
- c - 如何在c中传递二维子数组的起始索引?
- javascript - Javascript 表单数据对象提交文件到 $_FILES 服务器变量
- cmake - 尝试配置项目的 REGEX REPLACE 错误
- android-jetpack-compose - Jetpack 组合 Switch() TrackWidth、TrackStrokeWidth、ThumbDiameter
- django - Django 模板自动重载
- python - Flask 应用程序在通过设备的 ipv4 地址访问时返回 400 错误请求,但在 localhost 上正确返回
- c# - 收到 Opayo 服务器 API 重复确认
- r - 使用 tidyverse 过滤包含 R 中数据的列的数据框
- reactjs - 是否有任何 npm 包或任何解决方案可以从 weblogic 服务器访问文件