在Android中将图像从res \ drawable保存到SQLite [英] Save Image From res\drawable to SQLite in Android

查看:74
本文介绍了在Android中将图像从res \ drawable保存到SQLite的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

大家好
我想知道如何将图像保存到sqlite.我已经有保存在res \ drawable文件夹中的图像文件,我想将其保存到sqlite.我已完成以下操作:

SQLiteDatabase db = myclass.getWritableDatabase();
ImageView iv =(ImageView)findViewById(drawable.image);
Drawable d = iv.getBackground();
BitmapDrawable bitDw =(((BitmapDrawable)d);
位图bitmap = bitDw.getBitmap();
ByteArrayOutputStream流=新的ByteArrayOutputStream();
bitmap.compress(Bitmap.CompressFormat.JPEG,100,stream);


ContentValues cv = new ContentValues();
cv.put("Col_Name",stream.toByteArray());
db.insert("My_DB",null,cv);

请问有人可以帮助我吗?

Hi everyone
I''d like to know how to save image to sqlite. I already have image file which is stored in res\drawable folder and I want to save it to sqlite. I''ve done as followings:

SQLiteDatabase db= myclass.getWritableDatabase();
ImageView iv = (ImageView) findViewById(drawable.image);
Drawable d =iv.getBackground();
BitmapDrawable bitDw = ((BitmapDrawable) d);
Bitmap bitmap = bitDw.getBitmap();
ByteArrayOutputStream stream = new ByteArrayOutputStream();
bitmap.compress(Bitmap.CompressFormat.JPEG, 100, stream);


ContentValues cv=new ContentValues();
cv.put("Col_Name", stream.toByteArray());
db.insert("My_DB", null, cv);

pls anyone can help me ?

推荐答案

尝试以下解决方案
try below solution
InputStream bs = getResources().openRawResource(R.drawable.logion_pre);byte[] bytes = new byte[bs.available()];
bs.read(bytes);
String stringtostore = new String(bytes
);


这篇关于在Android中将图像从res \ drawable保存到SQLite的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆