【发布时间】:2016-11-17 06:35:47
【问题描述】:
我已经创建了静态数据库,并且这个数据库为图像添加了 base 64 字符串这个图像是大尺寸我已经运行了我的应用程序,同时获取数据库错误以获取字符串如何解决它。
我是android编程新手...
数据库
public List<People> getAllPeople() {
List<People> peoples = new ArrayList<>();
try {
SQLiteDatabase db = SQLiteDatabase.openDatabase(DB_PATH + DB_NAME, null, SQLiteDatabase.OPEN_READWRITE);
Cursor cursor = db.rawQuery("select * from " + TABLE_PEOPLE, null);
while (cursor.moveToNext()) {
if (cursor != null) {
String peopleImage = cursor.getString(cursor.getColumnIndex(PEOPLE_IMAGE));\\ This line getting error
String categoryId = cursor.getString(cursor.getColumnIndex(CATEGORY_ID));
String peopleName = cursor.getString(cursor.getColumnIndex(PEOPLE_NAME));
String peopleId = cursor.getString(cursor.getColumnIndex(ID));
int status = cursor.getInt(cursor.getColumnIndex(STATUS));
String month = cursor.getString(cursor.getColumnIndex(PEOPLE_MONTH));
String date = cursor.getString(cursor.getColumnIndex(PEOPLE_DATE));
String year = cursor.getString(cursor.getColumnIndex(PEOPLE_YEAR));
String peopleDetail = cursor.getString(cursor.getColumnIndex(PEOPLE_DETAIL));
People people = new People();
people.setId(peopleId);
people.setPeopleName(peopleName);
people.setPeopleImage(peopleImage);
people.setStatus(status);
people.setMonth(month);
people.setDate(date);
people.setYear(year);
people.setPeopleDetail(peopleDetail);
people.setCategoryId(categoryId);
peoples.add(people);
}
}
} catch (Exception e) {
Log.d("DB", e.getMessage());
}
return peoples;
}
适配器
byte[] decodedString = Base64.decode(people.getPeopleImage(), Base64.DEFAULT);
BitmapFactory.Options options = new BitmapFactory.Options();
options.inJustDecodeBounds = true;
BitmapFactory.decodeByteArray(decodedString, 0, decodedString.length, options);
options.inSampleSize = calculateInSampleSize(options, 100, 100);
options.inJustDecodeBounds = false;
Bitmap bmp1 = BitmapFactory.decodeByteArray(decodedString, 0, decodedString.length, options);
if (bmp1 != null) {
holder.ivPeopleImage.setImageBitmap(bmp1);
}
【问题讨论】:
-
那你为什么要使用
Base64呢? -
我已经在静态数据库中添加了base64编码字符串..@pskink
-
你知道base64是干什么用的吗?
-
我不知道?@pskink
-
因为使用简单,并且在解码后获取字符串,所以我使用 base64@pskink
标签: java android database bitmap base64