導航:首頁 > 編程大全 > android上傳圖片到資料庫

android上傳圖片到資料庫

發布時間:2023-07-20 08:23:35

❶ android如何將系統圖片存入資料庫

絕大大多數的系統,圖片一般不直接存儲到資料庫,不然圖片多的話很容易降低資料庫性能,圖片上傳後一般把圖片存儲到磁碟的目錄下,資料庫只存儲圖片路徑

❷ 使用android上傳圖片到伺服器,並且把圖片保存到伺服器的某個文件夾里

有兩種方法,第一,把你的圖片轉成位元組流,然後用post方法把位元組流傳到服務端,然後服務端接收到位元組流之後,開啟一個線程把它重新壓縮成圖片,保存在某個文件夾下面。
第二,開啟一個線程,用socket直接把圖片放到stream中傳到服務端,服務端接收後保存到文件夾下。

❸ 求助!android開發 如何將圖片添加進SQlite資料庫

//寫入資料庫
ByteArrayOutputStream os = new ByteArrayOutputStream();
ImageView pic = (ImageView) findViewById(R.id.picture);
Bitmap picdraw =pic.getDrawingCache(true)

picdraw.compress(Bitmap.CompressFormat.PNG, 100, os);

values.put("pic", os.toByteArray());
//從資料庫讀取
BitmapFactory.Options opts = new BitmapFactory.Options();

opts.inJustDecodeBounds = true;

BitmapFactory.decodeByteArray(c.getBlob(c.getColumnIndex("pic")), 0, c.getBlob(c.getColumnIndex("pic")).length,opts);

opts.inSampleSize = Common.computeSampleSize(opts, -1, 130*100);

opts.inJustDecodeBounds = false;

bmp = BitmapFactory.decodeByteArray(c.getBlob(c.getColumnIndex("pic")), 0, c.getBlob(c.getColumnIndex("pic")).length,opts);

downloader.setApkdraw(bmp);

❹ android怎麼將圖片傳送到伺服器,然後將圖片保存在mysql資料庫中

一般資料庫中是不保存圖片的,保存的是圖片存放路徑,圖片放到文件夾中,如果放到資料庫回中資料庫會答很大,影響讀取速度。
如果想放就把欄位定義為如:`img` longblob;
然後就可以讀取文件流 存儲到資料庫中了就可以了

❺ Android 圖片以位元組流方式存入本地資料庫 怎麼弄 求高手指點啊

少年,資料庫有個類型是blob,可以用這個類型存儲,直接存儲位元組,步驟:
1.假設圖片欄位名Image,那麼設置Image為blob欄位
2.代碼中將bimageview轉換為位元組以後,用ContentValues中的values.put("Image",byte[]);然後或者是插入,或者是更新,用android的sqlite3中的操作就可以了
如果你看上面的後半部分不太懂,可以網路一下:android sqlite3 的增刪改查,就會看到裡面有具體的步驟了,就是利用ContentValues進行sql語句處理

❻ 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上傳圖片到資料庫相關的資料

熱點內容
蘋果升級系統白屏 瀏覽:136
三菱gxplc編程軟體如何使用 瀏覽:710
海康威視手機app怎麼看不了 瀏覽:482
wordpress下載中心插件 瀏覽:402
微信限制字數是多少 瀏覽:20
策劃輸出主要從哪些文件來 瀏覽:174
網路營銷找什麼工作 瀏覽:372
tcl匹配文件名的正則表達式 瀏覽:461
音頻文件數據量為何8 瀏覽:534
有哪些分享學習的網站 瀏覽:174
小程序文件發到微信電腦如何打開 瀏覽:265
四星五星做號工具 瀏覽:920
qq郵箱怎麼發送視頻文件 瀏覽:453
能免費開店的網站有哪些 瀏覽:548
中國網路營銷發展史 瀏覽:828
違法紅頭文件有哪些 瀏覽:43
瀏覽器單文件版 瀏覽:982
騰訊視頻離線緩存文件 瀏覽:944
如何讓教育過好網路關 瀏覽:906
新版本vk10001p 瀏覽:13

友情鏈接