ImageView怎么绑定图片路径 在sqlite中存放图片路径,在程序中怎么给ImageView控件绑定图片。 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 路径的话,用这个void setImageURI(Uri uri) Url imagepath = Url.fromFile(new File("/sdcard/test.png"));imageview.setImageURI(imagepath); Uri imagepath = Uri.fromFile(new File("/images/2010091905110324.png"));PicImageView.setImageURI(imagepath); 把R.drawable.icon_name存到数据库里面,从数据库得到传入一个整形变量 icon_resource;iv.setImageDrawable(getResources().getDrawable(icon_resource)); 从数据库中把文件取出来,然后把获得的图片和imageView绑定 LZ看看下面这段代码有没有收获...public static final String TABLECONTACTS = "create table contacts("+ "_id INTEGER PRIMARY KEY," + "name TEXT NOT NULL,"+ "contactIcon BLOB," + "telPhone TEXT NOT NULL,"+ "groupName TEXT," + "birthday TEXT," + "address TEXT,"+ "email TEXT NOT NULL," + "description TEXT NOT NULL,"+ "createTime TEXT," + "modifyTime TEXT" + ");";public static final String TABLEGROUPS = "create table groups("+ "_id INTEGER PRIMARY KEY," + "groupName TEXT UNIQUE NOT NULL,"+ "createTime TEXT," + "modifyTime TEXT" + ");";public long inserDataToContacts(MyContacts contactInfo) {String formatTime = getSysNowTime();ContentValues content = new ContentValues();content.put("name", contactInfo.getName());content.put("birthday", contactInfo.getBirthday());content.put("address", contactInfo.getAddress());content.put("telPhone", contactInfo.getTelPhone());content.put("email", contactInfo.getEmail());content.put("contactIcon", contactInfo.getContactIcon());content.put("description", contactInfo.getDescription());content.put("groupName", contactInfo.getGroupName());content.put("createTime", formatTime);content.put("modifyTime", formatTime);return mSQLiteDatabase.insert(TABLE_CONTACTS, null, content);}MyContacts contactAllInfoCache=null;BitmapDrawable bd=(BitmapDrawable)mEditor.getDrawable();Bitmap bitMap=bd.getBitmap();contactAllInfoCache.setContactIcon(getBitmapByte(bitMap));取的时候就contactIcon.setImageBitmap(getBitmapFromByte(cursor.getBlob(icon_index))); public static Bitmap getBitmap(Context context, int id){ Bitmap bmp = null; int musicId = id; Uri uri = Uri.parse("content://media/external/audio/media/" + musicId + "/albumart"); ParcelFileDescriptor pfd = null; try { pfd = context.getContentResolver().openFileDescriptor(uri, "r"); } catch (FileNotFoundException e) { } if (pfd != null) { FileDescriptor fd = pfd.getFileDescriptor(); bmp = BitmapFactory.decodeFileDescriptor(fd); } return bmp; } int resId = (Integer) R.drawable.class.getField(imgName).get(null); img.setImageResource(resId);楼主 如果你的 image 唯一 项目的res目录下, 那么你可以借助反射。 在 sqlite中仅仅保存 图片的name就可以了因为每一个imgName都是drawable类的一个Field如果不是在项目的res等目录下。。 就另当别论了 我搞了这个问题 半个下午了 唉。分享一下 位于 项目的res目录下 打错了俩字。 不好意思 Android下载时怎么显示进度条 显示隐藏虚拟键盘 请问我有一个内核驱动模块fnm.ko,我想在内核启动后自动加载该如何做? android 应用创建快捷方式弹出toast问题 Android SDK下不了 android Uri获取IP 如何从后台service传递数据到前台正在运行的activity? 纠结,这家公司不知道该不该去 android Camera2 录像 TextureView 异常 困扰两天了 求大佬指点 求大神帮忙解决一个ndk开发的问题,在线等 数据库表中的记录删不掉也更新不了??? 针对竖屏开发UI,需要哪些必要的步骤?或者预置条件
void setImageURI(Uri uri)
imageview.setImageURI(imagepath);
PicImageView.setImageURI(imagepath);
iv.setImageDrawable(getResources().getDrawable(icon_resource));
public static final String TABLECONTACTS = "create table contacts("
+ "_id INTEGER PRIMARY KEY," + "name TEXT NOT NULL,"
+ "contactIcon BLOB," + "telPhone TEXT NOT NULL,"
+ "groupName TEXT," + "birthday TEXT," + "address TEXT,"
+ "email TEXT NOT NULL," + "description TEXT NOT NULL,"
+ "createTime TEXT," + "modifyTime TEXT" + ");";
public static final String TABLEGROUPS = "create table groups("
+ "_id INTEGER PRIMARY KEY," + "groupName TEXT UNIQUE NOT NULL,"
+ "createTime TEXT," + "modifyTime TEXT" + ");";public long inserDataToContacts(MyContacts contactInfo) {
String formatTime = getSysNowTime();
ContentValues content = new ContentValues();
content.put("name", contactInfo.getName());
content.put("birthday", contactInfo.getBirthday());
content.put("address", contactInfo.getAddress());
content.put("telPhone", contactInfo.getTelPhone());
content.put("email", contactInfo.getEmail());
content.put("contactIcon", contactInfo.getContactIcon());
content.put("description", contactInfo.getDescription());
content.put("groupName", contactInfo.getGroupName());
content.put("createTime", formatTime);
content.put("modifyTime", formatTime);
return mSQLiteDatabase.insert(TABLE_CONTACTS, null, content);}
MyContacts contactAllInfoCache=null;
BitmapDrawable bd=(BitmapDrawable)mEditor.getDrawable();
Bitmap bitMap=bd.getBitmap();
contactAllInfoCache.setContactIcon(getBitmapByte(bitMap));取的时候就
contactIcon.setImageBitmap(getBitmapFromByte(cursor
.getBlob(icon_index)));
Bitmap bmp = null;
int musicId = id;
Uri uri = Uri.parse("content://media/external/audio/media/" + musicId + "/albumart");
ParcelFileDescriptor pfd = null;
try {
pfd = context.getContentResolver().openFileDescriptor(uri, "r");
} catch (FileNotFoundException e) {
}
if (pfd != null) {
FileDescriptor fd = pfd.getFileDescriptor();
bmp = BitmapFactory.decodeFileDescriptor(fd);
}
return bmp;
}
img.setImageResource(resId);楼主 如果你的 image 唯一 项目的res目录下, 那么你可以借助反射。
在 sqlite中仅仅保存 图片的name就可以了
因为每一个imgName都是drawable类的一个Field如果不是在项目的res等目录下。。 就另当别论了 我搞了这个问题 半个下午了 唉。分享一下