转换的字节数组位图,从sqlite的检索 [英] convert byteArray to bitmap retrieved from sqlite
本文介绍了转换的字节数组位图,从sqlite的检索的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我想保存图像SQLite数据库,然后在以后检索。我已经保存它字节的形式[]。但没有形成位!
I am trying to save image in sqlite database and then retrieve it later. I have stored it in form of byte[]. BUt bitmap is not being formed!
存储图像:(BLOB类型)
Storing images: (blob type)
Drawable myDrawable = getResources().getDrawable(arr[i]);
myLogo = ((BitmapDrawable) myDrawable).getBitmap();
ByteArrayOutputStream stream = new ByteArrayOutputStream();
myLogo.compress(Bitmap.CompressFormat.JPEG, 100, stream);
b = stream.toByteArray();
我的code检索:
My code for retrieving:
byte[] Image;
Image = c.getBlob(c.getColumnIndex("img_str"));
BitmapFactory.Options options = new BitmapFactory.Options();
decodedByte = BitmapFactory.decodeByteArray(Image, 0,Image.length, options);
arr_img.add(decodedByte);
System.out.println("Image = " + Image);
System.out.println("decodedByte = " + decodedByte);
logcat的:
Logcat:
07-22 07:15:55.482: D/skia(19319): --- SkImageDecoder::Factory returned null
07-22 07:15:55.482: I/System.out(19319): Image = [B@4057ea48
07-22 07:15:55.482: I/System.out(19319): decodedByte = null
07-22 07:15:55.521: D/dalvikvm(19319): GC_EXPLICIT freed 114K, 50% free 2871K/5639K,external 5406K/5783K, paused 43ms
07-22 07:15:55.541: D/skia(19319): --- SkImageDecoder::Factory returned null
07-22 07:15:55.541: I/System.out(19319): Image = [B@40577aa0
07-22 07:15:55.541: I/System.out(19319): decodedByte = null
请帮忙,我很无能,为什么这是行不通的。谢谢
please help as i am clueless why this is not working. thanks
推荐答案
其实这个问题是不是与转换,但我是如何被存储的方式。
Actually the problem was not with the conversion but the way how i was storing it..
我用prepared语句插入值.. bindBlob()做的工作。
I used prepared statement to insert values.. bindBlob() did the job
String sql = "INSERT INTO demoImage (img_name,img_str) VALUES(?,?)";
SQLiteStatement insertStmt = dbsqlite.compileStatement(sql);
insertStmt.clearBindings();
insertStmt.bindString(1, name);
insertStmt.bindBlob(2, bal);
insertStmt.executeInsert();
这篇关于转换的字节数组位图,从sqlite的检索的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文