简体   繁体   English

如何从Android imageview获取图像并存储到db中

[英]how to get image from Android imageview and storing into db

如何从android图像视图获取图像以及如何将该值存储到数据库中?

you first get drawble from imageview你首先从 imageview 得到 drawble

Drawable d = yourimageview.getDrawable();

and then convert into byte array to store into database然后转换成字节数组存储到数据库中

BitmapDrawable bitmapDrawable = ((BitmapDrawable) drawable);
Bitmap bmp = bitmapDrawable .getBitmap();
ByteArrayOutputStream stream = new ByteArrayOutputStream();
bitmap.compress(bmp.CompressFormat.JPEG, 100, stream);
byte[] arr = stream.toByteArray();

now you can easily store byte array ie arr into database as blob.现在您可以轻松地将字节数组即 arr 作为 blob 存储到数据库中。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM