当前位置:首页 » 数据仓库 » android数据库读取图片
扩展阅读
webinf下怎么引入js 2023-08-31 21:54:13
堡垒机怎么打开web 2023-08-31 21:54:11

android数据库读取图片

发布时间: 2022-12-20 02:02:41

‘壹’ android 如何在listView中读取数据库中记录位置的图片,跪求小例子,谢谢给位大侠

R.drawable.xxx? 存变量名不方便吧 存变量的值 然后用SimpleAdapter就行
R.drawable.xxx也行 在程序中建一个map一一映射

‘贰’ android 如何获取保存的图片的地址 并存到数据库中

安卓中如何获取保存的图片uri 并保存到sqlite数据库中
有如下两种方法,仅供参考
方法一:Java代码

public void saveIcon(Bitmap icon) {
if (icon == null) {
return;
}
// 最终图标要保存到浏览器的内部数据库中,系统程序均保存为SQLite格式,Browser也不例外,因为图片是二进制的所以使用字节数组存储数据库的
// BLOB类型
final ByteArrayOutputStream os = new ByteArrayOutputStream();
// 将Bitmap压缩成PNG编码,质量为100%存储
icon.compress(Bitmap.CompressFormat.PNG, 100, os);
// 构造SQLite的Content对象,这里也可以使用
raw ContentValues values = new ContentValues();
// 写入数据库的
Browser.BookmarkColumns.TOUCH_ICON字段 values.put(Browser.BookmarkColumns.TOUCH_ICON, os.toByteArray());
DBUtil.update(....);
//调用更新或者插入到数据库的方法
}
}

方法二:如果数据表入口时一个content:URIJava代码

import android.provider.MediaStore.Images.Media;
import android.content.ContentValues;
import java.io.OutputStream;
// Save the name and description of an image in a ContentValues map.
ContentValues values = new ContentValues(3);
values.put(Media.DISPLAY_NAME, "road_trip_1");
values.put(Media.DESCRIPTION, "Day 1, trip to Los Angeles");
values.put(Media.MIME_TYPE, "image/jpeg");
// Add a new record without the bitmap, but with the values just set.
// insert() returns the URI of the new record.
Uri uri = getContentResolver().insert(Media.EXTERNAL_CONTENT_URI, values);
// Now get a handle to the file for that record, and save the data into it.
// Here, sourceBitmap is a Bitmap object representing the file to save to the database.
try {
OutputStream outStream = getContentResolver().openOutputStream(uri);
sourceBitmap.compress(Bitmap.CompressFormat.JPEG, 50, outStream);
outStream.close();
} catch (Exception e) {
Log.e(TAG, "exception while writing image", e);
}
原文请看http://www.bafenbaosoft.com/post/48.html

‘叁’ android中如何从数据库获取图片的路径

利用这个URI:content://media/internal/images
下面的链接地址很详细,我就不再这里饶舌了
主要看代码部分的380行的那个Activity

‘肆’ android小程序,从数据库中读取图片路径然后进行显示,不是背景图片

感觉这样应该可以,
先从数据库里面获得
这个图片的绝对路径
然后
使用UIL类
URL
url=new
URL(file:///路径);
然后得到这个文件的输入流InputStream
in=url.openStream();
然后得到此图片的位图Bitmap
bitmap=BitmapFactory.decodeStream(in);
ImageView
img=new
ImageView(this);
img.setImageBitmap(bitmap);
从网络上的话是这样,但是手机上是不是这样就不清楚了你可以试一下。
那个图片应该是要放在手机上。

‘伍’ android 如何读取数据库中的图片

从数据库读取二进制文件
然后从二进制读取的图片信息:
byte[] picData = cursor.getBlob(cursor.getColumnIndex("pic_data"));
bitmap.setImageBitmap(BitmapFactory.decodeByteArray(picData, 0, picData.length));

‘陆’ android:从数据库中取得的图片,无法显示到模拟器上

应该是你在byte【】转换成bitmap 时候 或者图片转换成byte【】数组时候出现错位等一些问题,导致图片不能正确显示, 我的图片一般都是存储路径的(把图片放在sdcard),然后显示的时候直接从路径读取,上传给服务器时候用fileInfutstream 读取指定路径下的图片 上传给服务器