Java 如何从Android imageview中获取图像并存储到db中
如何从android image view获取图像以及如何将该值存储到数据库中?首先从imageview获取drawbleJava 如何从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
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…,”);}能否请您更新您的问题。我无法正确查看代码