Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/fsharp/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Android 如何通过浏览在的sqllite数据库中添加图像?_Android - Fatal编程技术网

Android 如何通过浏览在的sqllite数据库中添加图像?

Android 如何通过浏览在的sqllite数据库中添加图像?,android,Android,我明白这一点 是否再次在数据库中添加相同的图像?再次,我想通过浏览库添加我自己选择的新图像,并将其上载和保存到数据库中 代码的输出如下所示 我在main.xml中添加了一个名为browsebutton的新按钮。并设置为打开图库的功能,但如何将浏览图像上载到数据库?请帮助我,我想从图库中添加我自己的img。et代码如何添加数据库我的图库图像 import android.app.Activity; import android.content.Intent; import android.g

我明白这一点

是否再次在数据库中添加相同的图像?再次,我想通过浏览库添加我自己选择的新图像,并将其上载和保存到数据库中

代码的输出如下所示

我在main.xml中添加了一个名为browsebutton的新按钮。并设置为打开图库的功能,但如何将浏览图像上载到数据库?请帮助我,我想从图库中添加我自己的img。et代码如何添加数据库我的图库图像

   import android.app.Activity;
import android.content.Intent;
import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.os.Bundle;
import android.util.Log;
import android.view.View;
import android.widget.Button;
import android.widget.ListView;

 public class SQLiteDemoActivity extends Activity {
private static final int SELECT_PICTURE = 1;
ArrayList<Contact> imageArry = new ArrayList<Contact>();
ContactImageAdapter adapter;
Button BrowseButton;

 /** Called when the activity is first created. */
 @Override
 public void onCreate(Bundle savedInstanceState) {
 super.onCreate(savedInstanceState);
 setContentView(R.layout.main);

 DataBaseHandler db = new DataBaseHandler(this);
//get image from drawable
Bitmap image = BitmapFactory.decodeResource(getResources(),
R.drawable.facebook);


BrowseButton=(Button)findViewById(R.id.BrowseButton);



BrowseButton.setOnClickListener(new View.OnClickListener() {

@Override
public void onClick(View v) {
    // TODO Auto-generated method stub
     // in onCreate or any event where your want the user to
    // select a file
    Intent intent = new Intent();
    intent.setType("image/*");
    intent.setAction(Intent.ACTION_GET_CONTENT);
    startActivityForResult(Intent.createChooser(intent,
            "Select Picture"), SELECT_PICTURE);

 }
});




//convert bitmap to byte
 ByteArrayOutputStream stream = new ByteArrayOutputStream();
 image.compress(Bitmap.CompressFormat.JPEG, 100, stream);
 byte imageInByte[] = stream.toByteArray();
/**
* CRUD Operations
* */
//Inserting Contacts
Log.d("Insert: ", "Inserting ..");
db.addContact(new Contact("FaceBook", imageInByte));
//display main List view bcard and contact name

//Reading all contacts from database
List<Contact> contacts = db.getAllContacts();
for (Contact cn : contacts) {
String log = "ID:" + cn.getID() + " Name: " + cn.getName()
+ " ,Image: " + cn.getImage();

//Writing Contacts to log
Log.d("Result: ", log);
 //add contacts data in arrayList
imageArry.add(cn);

}
adapter = new ContactImageAdapter(this, R.layout.screen_list,
imageArry);
ListView dataList = (ListView) findViewById(R.id.list);
dataList.setAdapter(adapter);
}
}

不要尝试在数据库中保存图像。将图像保存到外部存储器中,并将其路径保存到数据库中。

但我确实喜欢此图像保存到数据库中此我的示例代码成功地将图像保存到数据库中,但保存硬代码图像Facebook.jpg我想通过浏览图像gellery并选择图像来保存img我想动态地将图像添加到图像视图中