我是Android开发的新手,我希望你能帮助我。
我可以使用以下代码保存图像路径
@Override
public void onActivityResult( int requestCode, int resultCode, Intent data) {
super.onActivityResult(requestCode, resultCode, data);
if (resultCode == Activity.RESULT_OK){
Uri targetUri = data.getData();
picture_location = targetUri.toString();
studentsDbAdapter.insertImagePath(studID ,picture_location);
}
}
我正在尝试使用以下代码从路径设置图像视图:
public void showpic() {
LoginDataBaseAdapter db = loginDataBaseAdapter.open();
boolean emptytab = false;
boolean empty = db.checkPic(null, emptytab);
//Cursor cursor = loginDataBaseAdapter.fetchProfileImageFromDatabase();
if(empty==false)
{
String pathName = studentsDbAdapter.getImapath(studID);
try {
InputStream path = getAssets().open(pathName);
Bitmap bit = BitmapFactory.decodeStream(path);
targetImage.setImageBitmap(bit);
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
}
但它没有显示任何内容。我希望你能帮助我。
这是我的checkpic代码:
public boolean checkPic(String count, Object object) {
boolean empty = false;
Cursor cursor = mDb.rawQuery("SELECT count(*) FROM ImagePath", null);
if(cursor != null)
{
cursor.moveToFirst();
if(cursor.getInt(0)== 0)
{
empty = true; //rows not null;
}
else
{
empty = false; // rows null;
}
}
return empty;
}