當前位置:首頁 » 安卓系統 » androidsqlite存儲圖片

androidsqlite存儲圖片

發布時間: 2022-08-02 07:54:08

A. android中使用sqlite資料庫存儲圖片信息

開程序啟動的時候用流直接到database目錄下就可以直接調用了.

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

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

C. android中調用手機相冊做頭像怎麼把圖片存取到sqlite資料庫啊

我回答過你了,你怎麼又開了一個貼:
http://..com/question/163893892118020

D. Android sqlite如何實現存儲圖片路徑

String 類型的

E. android sqlite中 資料庫存入圖片名稱,查詢得到cursor數據,求放入listview的源碼

代碼:
if(username.length()>0&&password.length()>0)
{
SQLiteAdapter db=new SQLiteAdapter(Main.this);
db.openToWrite();
if(db.Login(username,password))
{
System.out.println("goutham");
Intent intent=new Intent(getApplicationContext(),ExampleActivity.class);

startActivity(intent);
}

F. android開發中如何在sqlite中創建一個的一個表和該表對應的方法類,目前最頭疼的就是圖標的圖片存取了

下面這個文件創建了Book.db,創建了表book,另外提供兩個簡單的方法,裡面有很多不完善的地方,沒有一一寫出來。時間有限,希望能幫助到你。

import android.content.ContentValues;
import android.content.Context;
import android.database.Cursor;
import android.database.sqlite.SQLiteDatabase;
import android.database.sqlite.SQLiteOpenHelper;
import android.graphics.Bitmap;
import android.graphics.BitmapFactory;

import java.io.ByteArrayOutputStream;

import static com.ume.myapplication.Columns.BOOK_AUTHOR;

/**
* _ Created by AlphaGo on 2017/3/11. just simple sample
*/

public class BookDbHelper extends SQLiteOpenHelper {
public static final String DB_NAME = "Book.db";
public static final String TABLE_BOOK = "Book";
public static final int DB_VERSION = 1;

private Context mContext;

public BookDbHelper(Context context) {
super(context, DB_NAME, null, DB_VERSION);
mContext = context;
}

@Override
public void onCreate(SQLiteDatabase db) {

createBookmarkTbl(db);
}

@Override
public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) {

}

private void createBookmarkTbl(SQLiteDatabase db) {
db.execSQL("CREATE TABLE IF NOT EXISTS " + TABLE_BOOK + "("
+ Columns._ID + " INTEGER PRIMARY KEY AUTOINCREMENT,"
+ BOOK_AUTHOR + " TEXT,"
+ Columns.BOOK_INTRODUCTION + " TEXT,"
+ Columns.BOOK_LABEL + " TEXT ,"
+ Columns.BOOK_NAME + " INTEGER NOT NULL DEFAULT 0,"
+ Columns.BOOK_PRICE + " FLOAT,"
+ Columns.BOOK_STOCK + " INTEGER NOT NULL,"
+ Columns.BOOK_ICON + " BLOB"
+ ");");
}

/**
* Insert Item
*/

public long insertItem(Book book) {
long id;
ContentValues initValues = new ContentValues();
ByteArrayOutputStream os = new ByteArrayOutputStream();
book.icon.compress(Bitmap.CompressFormat.PNG, 100, os);
initValues.put(BOOK_AUTHOR, book.author);
initValues.put(Columns.BOOK_INTRODUCTION, book.introction);
initValues.put(Columns.BOOK_LABEL, book.label);
initValues.put(Columns.BOOK_NAME, book.name);
initValues.put(Columns.BOOK_PRICE, book.price);
initValues.put(Columns.BOOK_STOCK, book.stock);
initValues.put(Columns.BOOK_ICON, os.toByteArray());
SQLiteDatabase db = getWritableDatabase();
id = db.insert(TABLE_BOOK, null, initValues);
db.close();
return id;
}

/**
* retrieve item by database index
*/

public Book getItemByIndex (int index){
Book book = new Book();

SQLiteDatabase db = getWritableDatabase();
Cursor cursor = db.query(TABLE_BOOK, null, "_id =?", new String[]{String.valueOf(index)}, null, null, null);
while (cursor.moveToNext()){
int id = cursor.getInt(0);
String author = cursor.getString(1);
String introction = cursor.getString(2);
String label = cursor.getString(3);
String name = cursor.getString(4);
float price = cursor.getFloat(5);
int stock = cursor.getInt(6);
byte[] bytes = cursor.getBlob(7);
Bitmap icon = BitmapFactory.decodeByteArray(bytes, 0, bytes.length);
book.icon = icon;
// TODO: 2017/3/11 one more thing
}
return book;
}

private static class Book {
public String author;
public String introction;
public String label;
public String name;
public float price;
public int stock;
public Bitmap icon;
}
}

G. android中怎麼用sqlite存儲一個map

在進行Android開發過程中,我們經常會接觸到Drawable對象(官方開發文檔:A Drawable is a general abstraction for "something that can be drawn."),那麼,若要使用資料庫來進行存儲及讀取,該如何實現?
一、存儲

//第一步,將Drawable對象轉化為Bitmap對象

Bitmap bmp = (((BitmapDrawable)tmp.image).getBitmap());

//第二步,聲明並創建一個輸出位元組流對象

ByteArrayOutputStream os = new ByteArrayOutputStream();

//第三步,調用compress將Bitmap對象壓縮為PNG格式,第二個參數為PNG圖片質量,第三個參數為接收容器,即輸出位元組流os

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

//第四步,將輸出位元組流轉換為位元組數組,並直接進行存儲資料庫操作,注意,所對應的列的數據類型應該是BLOB類型

ContentValues values = new ContentValues();

values.put("image", os.toByteArray());

db.insert("apps", null, values);

db.close();

H. android開發,如何把圖庫中一張選中的照片,寫入到APP的SQLite或者私有文件夾

首先你能不能獲取到圖庫中的圖片,如果你已經獲取了圖庫中的圖片了,那麼把圖片放到資料庫中的代碼我給你,如果沒有獲取到圖片,那你就先獲取圖片了再說咯

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

圖片等二進制媒體數據可以保存到BLOB類型的欄位里,例子:

http://blog.csdn.net/zhouyongyang621/archive/2010/03/26/5418586.aspx

但是一般不推薦這么做,因為如果保存大量媒體數據那麼資料庫的大小會激增,導致資料庫訪問性能下降。還是把圖保存到文件里,然後在資料庫里加個欄位引用文件路徑吧。

建議你盡可能把圖保存到SD卡上(/sdcard),如果沒有SD卡就保存到應用程序的私有目錄里(/data/data/packagename/)

J. 怎樣解決android SQLite 圖片是以圖片的存儲路徑的方式存儲的,讀取並顯示在GridVi.

String
picPath
=
c.getString(c.getColumnIndex("pic"));BitmapFactory.Options
options
=
new
BitmapFactory.Options();
options.inSampleSize
=
2;
Bitmap
bitmap
=
BitmapFactory.decodeFile(picPath,
options);CheckMenu
cm
=
new
CheckMenu();
cm.setBm(bitmap);list.add(cm);//list
是這樣定義的List
list
=
new
ArrayList();//在GridView的getview(),里我自定義了一個布局imageView
=
(ImageView)
v.findViewById(R.id.diancai_view_ImageView01);CheckMenu
cm
=
(CheckMenu)
list.get(position);imageView.setImageBitmap(cm.getBm());請問這幾行代碼有問題嗎?
為什我我運行就是現實不出來圖片,而且沒有報錯信息!

熱點內容
存儲標准性 發布:2024-05-03 13:37:07 瀏覽:416
液鹼存儲 發布:2024-05-03 13:21:13 瀏覽:156
linux如何改配置文件 發布:2024-05-03 13:00:54 瀏覽:31
哪個安卓模擬器老爺機帶得動 發布:2024-05-03 13:00:49 瀏覽:576
編程與實戰 發布:2024-05-03 12:54:30 瀏覽:38
電腦開機有密碼rpc伺服器不可用 發布:2024-05-03 12:40:54 瀏覽:471
硬體的演算法 發布:2024-05-03 12:34:28 瀏覽:388
支付密碼為什麼就六位 發布:2024-05-03 12:29:17 瀏覽:920
腳本找書 發布:2024-05-03 12:02:17 瀏覽:493
境外伺服器租用怎麼辦 發布:2024-05-03 11:45:34 瀏覽:944