图片在数据库表中定义的是Blob类型,但是查找的时候显示为byte[]不能定义,不知道是怎么回事,求指导🙏🏻
参考:https://blog.csdn.net/yihuliunian/article/details/104814035/
不知道你这个问题是否已经解决, 如果还没有解决的话:我来回答一下这个问题:
ByteArrayOutputStream baos = new ByteArrayOutputStream();
bitmap.compress(Bitmap.CompressFormat.PNG, 100, baos);
byte[] data = baos.toByteArray();
ContentValues values = new ContentValues();
values.put(MySQLiteHelper.COLUMN_PICTURE, data);
database.insert(MySQLiteHelper.TABLE_NAME, null, values);
Cursor cursor = database.query(MySQLiteHelper.TABLE_NAME, allColumns, null, null, null, null, null);
cursor.moveToFirst();
byte[] imageData = cursor.getBlob(cursor.getColumnIndexOrThrow(MySQLiteHelper.COLUMN_PICTURE));
Bitmap bitmap = BitmapFactory.decodeByteArray(imageData, 0, imageData.length);
imageView.setImageBitmap(bitmap);