Ⅰ 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 如何在listView中讀取資料庫中記錄位置的圖片,跪求小例子,謝謝給位大俠
R.drawable.xxx? 存變數名不方便吧 存變數的值 然後用SimpleAdapter就行
R.drawable.xxx也行 在程序中建一個map一一映射
Ⅲ android:從資料庫中取得的圖片,無法顯示到模擬器上
應該是你在byte【】轉換成bitmap 時候 或者圖片轉換成byte【】數組時候出現錯位等一些問題,導致圖片不能正確顯示, 我的圖片一般都是存儲路徑的(把圖片放在sdcard),然後顯示的時候直接從路徑讀取,上傳給伺服器時候用fileInfutstream 讀取指定路徑下的圖片 上傳給伺服器
Ⅳ android開發: EditText中插入的相冊圖片如何保存在資料庫里,查看的時候又如何讀取
保存一個url是個不錯的方法,然後載入的時候就可以根據路徑去生成一個bitmap對象,再把這個對象顯示到組件上 。如果知道路徑,那麼顯示時調用BitmapFactory.decodeFile(String pathName)這個方法就行,參數為一個路徑字元串.
Ⅳ android中如何從資料庫獲取圖片的路徑
利用這個URI:content://media/internal/images
下面的鏈接地址很詳細,我就不再這里饒舌了
主要看代碼部分的380行的那個Activity
Ⅵ android 如何讀取資料庫中的圖片
從資料庫讀取二進制文件
然後從二進制讀取的圖片信息:
byte[] picData = cursor.getBlob(cursor.getColumnIndex("pic_data"));
bitmap.setImageBitmap(BitmapFactory.decodeByteArray(picData, 0, picData.length));
Ⅶ android 存在資料庫中的動態圖片,如何讀取出來,顯示在ImageView中
實現的功能為從伺服器獲取圖片數據,在布局頁面上顯示。由於圖片的個數是不確定的,因此採用在布局頁面中定義多個ImageView來顯示圖片是不合理的。
(一)首先定義布局
android:id="@+id/id_layout_movie"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
/>
(二)載入圖片顯示時獲取到布局文件
RelativeLayout rl_Movie = (RelativeLayout) findViewById(R.id.id_layout_movie);
(三)依次循環伺服器獲取的圖片數據,一張一張設置圖片顯示的位置
//newWidth為圖片顯示的寬度,newHeight為圖片顯示的高度
RelativeLayout.LayoutParams lp1 = new RelativeLayout.LayoutParams( newWidth, newHeight);
設置lp1.leftMargin和lp1.topMargin的值
(四)最後設置rl_Movie.addView(iv, lp1)將圖片加入布局文件中
Ⅷ android開發如何把資料庫中圖片路徑轉成圖片讀取顯示
通過流的形式就可以了。通過路徑得到文件流,然後使用bitmapfactory.decodeStream 方法 得到一個bitmap 然偶通過imageView.setImageBitmap()就ok了
Ⅸ 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