lire image blob créée par android
Bonjour,
Voici le problème:
Sous android:à partir d'une view,sauvegarde d'une image dans un blob Mysql:
Code:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15
|
Bitmap b = maview.getDrawingCache();
...
ByteArrayOutputStream bos=new ByteArrayOutputStream();
b.compress(Bitmap.CompressFormat.PNG,100,bos);
byte[] img=bos.toByteArray();
ContentValues cv=new ContentValues();
cv.put("image", img);
...
String query="insert into ma_table(...,champ_blob,...)" +
" values('"...+"'",+cv+"','"..."')";
Statement stmt = con.prepareStatement(query);
stmt.executeUpdate(query); |
Tout est normal dans ma_table j'obtiens bien :image=[B@9327312
Puis je cherche à lire cette image par 1 servlet java:
Code:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19
|
ps = conn.prepareStatement("select champ_blob from ma_table where id = ?");
ps.setString(1,id);
ResultSet rs = ps.executeQuery();
rs.next();
b=rs.getBlob("champ_blob");
InputStream is = b.getBinaryStream();
OutputStream os = response.getOutputStream();
byte buf[] = new byte[(int) b.length()];
is.read(buf);
os.write(buf);
os.close();
response.reset();
response.setBufferSize(DEFAULT_BUFFER_SIZE);
response.setContentType("image/png");
response.setContentLength( (int) b.length()); |
mais je n'obtiens pas l'image.
Que se passe t'il?
D'avance merci.