首页 > 解决方案 > 如何从imagebutton获取位图

问题描述

当我ImageButton点击它时,画廊将出现以选择图像并发送bitmap回以显示在此ImageButton。但我必须得到bitmap这个 ImageButton 上显示的内容,然后将其保存到数据库中byte[]

标签: javaandroidsqlite

解决方案


首先bitmapImgaeButton

Bitmap bitmap = ((BitmapDrawable)imageButton.getDrawable()).getBitmap();

然后将其转换bitmapbyteArray

ByteArrayOutputStream outputStream = new ByteArrayOutputStream();
bitmap.compress(Bitmap.CompressFormat.PNG, 100, outputStream);
byte[] byteArray = outputStream.toByteArray();

推荐阅读