on 2014 Jun 11 5:57 AM
I would like to insert an image into ultralitej-db (Android) and later get it from db to display it again.
I'm able to insert and select it from db but the displayed image is all black.
insert-code:
ps = mConn.prepareStatement(query); OutputStream os = ps.getBlobOutputStream(1); os.write(photo); success = ps.execute(); ps.close();
select-code:
rs.first(); InputStream is = rs.getBlobInputStream("Picture"); ByteArrayOutputStream buffer = new ByteArrayOutputStream(); int nRead; byte[] bytes = new byte[16384]; try { while ((nRead = is.read(bytes, 0, bytes.length)) != -1) { buffer.write(bytes, 0, nRead); } buffer.flush(); is.close(); } catch (IOException e) { e.printStackTrace(); }
UPDATE it seems that the insert is wrong. i selected other images which are already stored in the db. they are displayed correctly.
Request clarification before answering.
better late than never. i found the solution for my problem. it was a converting/format thing with jpeg.
i used
mBitmap.compress(Bitmap.CompressFormat.JPEG, 100, bos);
and got the whole black image.
then i tried mBitmap.compress(Bitmap.CompressFormat.PNG, 100, bos);
and it works.
thanks to all who gave me advices to solve the problem
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
User | Count |
---|---|
52 | |
6 | |
5 | |
5 | |
5 | |
4 | |
3 | |
3 | |
3 | |
3 |
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.