當前位置:首頁 » 數據倉庫 » 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 讀取指定路徑下的圖片 上傳給伺服器