當前位置:首頁 » 安卓系統 » androiduri獲取圖片

androiduri獲取圖片

發布時間: 2022-06-02 08:11:10

㈠ android:怎樣將Uri類型的圖片數據轉換成流

ContentResolver resolver = getContentResolver();

Cursor cursor = resolver.query(originalUri, proj, null, null, null);
// 按我個人理解 這個是獲得用戶選擇的圖片的索引值
int column_index = cursor.getColumnIndexOrThrow(MediaStore.Images.Media.DATA);
// 將游標移至開頭 ,這個很重要,不小心很容易引起越界
cursor.moveToFirst();
// 最後根據索引值獲取圖片路徑
String path = cursor.getString(column_index);

這樣就獲得了圖片的路徑。

下面說圖片上傳,現在一般上傳都用Okhttp 框架了,直接上傳個File類就可以,不需要自己在轉成數據流,給你個連接,我寫的工具類,你也可以查一下,這個很方便http://blog.csdn.net/xihe9152/article/details/68485040,使用前需要先依賴Okhttp3

java">

㈡ android中怎麼跳轉到相冊獲取照片並得到url

方法/步驟
1
如下圖所示,需要根據URL地址獲取圖片載入到圖中Anroid機器人所在的位置,這是運行前的效果:

2
首先需根據URL地址獲取圖片,如下所示,urladdr即為圖片地址,返回Drawable對象:
//download image from network using @urladdress
private Drawable loadImageFromNetwork(String urladdr) {
// TODO Auto-generated method stub
Drawable drawable = null;
try{
//judge if has picture locate or not according to filename
drawable = Drawable.createFromStream(new URL(urladdr).openStream(), "image.jpg");
}catch(IOException e){
Log.d("test",e.getMessage());
}
if(drawable == null){
Log.d("test","null drawable");
}else{
Log.d("test","not null drawable");
}
return drawable;
}
3
獲取到圖片後,需要更新主線程UI資源,考慮到時間以及界面反應延遲等,所以採用線程加以處理,如下圖所示:
// image
new Thread(new Runnable(){
Drawable drawable = loadImageFromNetwork(urladdress);
@Override
public void run(){
//post() is quite important,update pictures in UI main thread
image.post(new Runnable(){
@Override
public void run(){
//TODO Auto-generated method stub
image.setImageDrawable(drawable);
}
});
}

//download image from network using @urladdress
private Drawable loadImageFromNetwork(String urladdr) {
//... 略(如 1 中所示)
}
}).start(); //線程啟動
4
說明:在上述示例代碼中,image是ImageView類的一個對象,也就是APP中的一個顯示圖像組件,利用獲取到的圖片drawable去更新image,運行效果如下所示:

㈢ Android獲取資料庫圖片uri路徑並用imageView顯示

我想問你最後怎麼解決的,我也是這個問題,網上也查不到解決方法,很煩!

㈣ 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 兩個Activity之間怎樣使用Uri傳遞圖片,怎樣獲取圖片的Uri,怎樣通過Uri得到圖片

為什麼使用Uri傳圖片呢?
你用Intent把圖片的地址傳到另一個Activity就OK了,或者把圖片對象用Intent傳也是Ok的。

㈥ Android如何獲取網路圖片

android中獲取網路圖片是一件耗時的操作,如果直接獲取有可能會出現應用程序無響應(ANR:Application Not Responding)對話框的情況。對於這種情況,一般的方法就是耗時操作用線程來實現。下面列三種獲取url圖片的方法:


  1. 直接獲取:(容易:ANR,不建議)

mImageView=(ImageView)this.findViewById(R.id.imageThreadConcept);
Drawabledrawable=loadImageFromNetwork(IMAGE_URL);
mImageView.setImageDrawable(drawable);

2. 後台線程獲取url圖片:

mImageView=(ImageView)this.findViewById(R.id.imageThreadConcept);
newThread(newRunnable(){
Drawabledrawable=loadImageFromNetwork(IMAGE_URL);
@Override
publicvoidrun(){

//post()特別關鍵,就是到UI主線程去更新圖片
mImageView.post(newRunnable(){
@Override
publicvoidrun(){
//TODOAuto-generatedmethodstub
mImageView.setImageDrawable(drawable);
}});
}

}).start();

3.AsyncTask獲取url圖片

mImageView=(ImageView)this.findViewById(R.id.imageThreadConcept);
newDownloadImageTask().execute(IMAGE_URL);
<String,Void,Drawable>
{

(String...urls){
returnloadImageFromNetwork(urls[0]);
}
protectedvoidonPostExecute(Drawableresult){
mImageView.setImageDrawable(result);
}
}

㈦ android 如何得到指定文件夾下圖片的uri,急急急急急

需要先在手機上安裝一個程序「R.E文件管理器」,然後打開這個程序裡面可以找到你想要的所有文件。

㈧ android 使用URL獲取本地的文件

public String getFromAssets(String fileName){
try {
InputStreamReader inputReader = new InputStreamReader( getResources().getAssets().open(fileName) );
BufferedReader bufReader = new BufferedReader(inputReader);
String line="";
String Result="";
while((line = bufReader.readLine()) != null)
Result += line;
return Result;
} catch (Exception e) {
e.printStackTrace();
}
}

熱點內容
共享文件夾沒有啟動伺服器服務 發布:2025-05-20 13:43:38 瀏覽:802
天龍八部游戲怎麼切換伺服器 發布:2025-05-20 13:42:36 瀏覽:630
亞馬遜免費主機是什麼配置 發布:2025-05-20 13:40:10 瀏覽:695
存儲類型默認分配 發布:2025-05-20 13:32:26 瀏覽:662
qq信息加密 發布:2025-05-20 13:31:32 瀏覽:341
文件夾嗅探器foldersniffer 發布:2025-05-20 12:33:36 瀏覽:912
編譯裝入 發布:2025-05-20 12:32:48 瀏覽:562
萬勝壓縮機價格 發布:2025-05-20 12:20:00 瀏覽:987
判斷雲伺服器是否誠實的存放數據 發布:2025-05-20 12:11:07 瀏覽:377
c語言基礎書 發布:2025-05-20 12:11:00 瀏覽:780