Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/android/201.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java 如何从Android imageview中获取图像并存储到db中_Java_Android_Performance_Web Services_Rest - Fatal编程技术网

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

Java 如何从Android imageview中获取图像并存储到db中,java,android,performance,web-services,rest,Java,Android,Performance,Web Services,Rest,如何从android image view获取图像以及如何将该值存储到数据库中?首先从imageview获取drawble Drawable d = yourimageview.getDrawable(); 然后转换成字节数组存储到数据库中 BitmapDrawable bitmapDrawable = ((BitmapDrawable) drawable); Bitmap bmp = bitmapDrawable .getBitmap(); ByteArrayOutputStream str

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

首先从imageview获取drawble

Drawable d = yourimageview.getDrawable();
然后转换成字节数组存储到数据库中

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

现在,您可以轻松地将字节数组(即arr)作为blob存储到数据库中。

我使用了它。但我没有存储正确的值Bitmap b=((BitmapDrawable)iv.getDrawable()).getBitmap();ByteArrayOutputStream bos=新建ByteArrayOutputStream();b.压缩(Bitmap.CompressFormat.PNG,100,bos);logo=bos.toByteArray();以及如何在datbase中存储。我像public void postHotel(MultivaluedMap hotelParams)一样存储,抛出SQLException{byte[]imgLogo=hotelParams.getFirst(“hotel_徽标”).getBytes(Charset.forName(“UTF-8”);System.out.println(“成功进入post=”+imgLogo.length);stm.executeUpdate(“插入酒店(hotel_徽标)”值(“+imgLogo+”);”;System.out.println(“Saave Successfully…,”);}能否请您更新您的问题。我无法正确查看代码