在我的应用程序中,我从库中上传图像,我想将此图像存储在SQLite数据库中.如何在数据库中存储位图?我正在将位图转换为字符串并将其保存在数据库中.从数据库中检索它时,我无法将该字符串分配给ImageView,因为它是一个字符串.
Imageupload12 .java:
public class Imageupload12 extends Activity {
Button buttonLoadImage;
ImageView targetImage;
int i = 0;
Database database = new Database(this);
String i1;
String img;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main5);
buttonLoadImage = (Button) findViewById(R.id.loadimage);
targetImage = (ImageView) findViewById(R.id.targetimage);
Bundle b = getIntent().getExtras();
if (b != null) {
img = b.getString("image");
targetImage2.setImageURI("image");
//i am getting error as i cant assign string to imageview.
}
buttonLoadImage.setOnClickListener(new Button.OnClickListener() {
public void onClick(View arg0) {
// TODO Auto-generated method stub …Run Code Online (Sandbox Code Playgroud) 我有一个sqlite数据库,它将从一个带有初始1000记录的web服务中填充,然后我将在每次需要时插入更多记录.我的问题是在哪里将sqlite数据库存储在设备中以便继续插入(在内部或外部存储器中),即如果我将数据库存储在内部存储器中并且当内部存储器被填充时我可以将其移动到外部并继续插入或者 如果我将它存储在外部存储器中并且外部存储器被填满并且内部有可用空间我可以移动到内部并继续插入数据..我很困惑这可以帮助我任何建议或链接请
我想使用游标从sqlite数据库中显示imageview中的图像.我使用下面的代码来检索图像,但我无法在imageview中显示图像.
Cursor c=this.db.query(TABLE_NAME, new String[] { "name","price","image" },
null, null, null, null, null);
name.setText(c.getString(0));
price.setText(c.getString(1));
byte b[]=c.getBlob(2);
Bitmap bp=BitmapFactory.decodeByteArray(b, 0, b.length);
ImageView image=(ImageView)findViewById(R.id.ImageView);
//ByteArrayInputStream imageStream = new ByteArrayInputStream(b);
//Bitmap theImage = BitmapFactory.decodeStream(imageStream);
//image.setImageBitmap(theImage);
image.setImageBitmap(bp);
Run Code Online (Sandbox Code Playgroud)
除图像外,将显示名称和价格,但不显示图像.任何可以帮助我解决这个问题的建议或代码.
请帮我.
提前致谢..
我使用下面的代码插入Uri图像SQLite:
寄存器
private void insertData( String name,String pass, Uri image) throws SQLiteException {
database = mdb.getWritableDatabase();
ContentValues cv = new ContentValues();
cv.put(MyDatabaseHelper.KEY_NAME, name);
cv.put(MyDatabaseHelper.KEY_PASSWORD, pass);
try {
database = mdb.getWritableDatabase();
InputStream iStream = getContentResolver().openInputStream(image);
byte[] inputData = Utils.getBytes(iStream);
cv.put(MyDatabaseHelper.KEY_IMAGE,inputData);
}catch(IOException ioe)
{
Log.e(TAG, "<saveImageInDB> Error : " + ioe.getLocalizedMessage());
}
database.insert(MyDatabaseHelper.TABLE_USER, null, cv);
Toast.makeText(getApplicationContext(),"Database Created",Toast.LENGTH_SHORT).show();
database.close();
}
Run Code Online (Sandbox Code Playgroud)
在我得到的时候Database Created,我假设数据库已成功创建并插入了数据.
在Login中,我想要SQLite根据用户名检索图像.
name = (EditText) findViewById(R.id.name);
name.addTextChangedListener(new TextWatcher() {
@Override
public void …Run Code Online (Sandbox Code Playgroud) 我正在尝试从数据库 sqlite 上的 ImageView 保存一个 Bitmat,但我做不到。
我保存字符串,但我不知道图像。
我的代码
BBDD 类
public class BBDD extends SQLiteOpenHelper
{
String create = "CREATE TABLE info(usuario TEXT, " +
"ma TEXT, " +
"ti TEXT, " +
"loc TEXT, " +
"lati TEXT, " +
"longi TEXT, " +
"obs TEXT," +
"date TEXT, " +
"time TEXT, " +
"in TEXT, " +
"imgone BLOB, " +
"imgtwo BLOB, " +
"imgthree BLOB, " +
"imgfour BLOB) ";
public BBDD (Context contexto, String …Run Code Online (Sandbox Code Playgroud) 我需要知道在eclipse中定义blob数据类型.我正在为Android开发一个应用程序,我想在数据库中保存图像和记录.我知道必须使用blob作为数据类型.我的问题是如何在类和DBhandler类中定义它.有人可以帮我提供代码帮助.