第七色在线视频,2021少妇久久久久久久久久,亚洲欧洲精品成人久久av18,亚洲国产精品特色大片观看完整版,孙宇晨将参加特朗普的晚宴

為了賬號安全,請及時(shí)綁定郵箱和手機(jī)立即綁定
已解決430363個(gè)問題,去搜搜看,總會(huì)有你想問的

如何在SQLite數(shù)據(jù)庫中存儲圖像

如何在SQLite數(shù)據(jù)庫中存儲圖像

如何在SQLite數(shù)據(jù)庫中存儲圖像在我的應(yīng)用程序中,我從圖片庫上傳一個(gè)圖像,并希望將該圖像存儲在SQLite數(shù)據(jù)庫中。如何在數(shù)據(jù)庫中存儲位圖?我正在將位圖轉(zhuǎn)換為字符串,并將其保存在數(shù)據(jù)庫中。當(dāng)從數(shù)據(jù)庫檢索它時(shí),我無法將該字符串分配給ImageView,因?yàn)樗且粋€(gè)字符串。Imageupload 12.java: public class Imageupload12 extends Activity {   Button buttonLoadImage;   ImageView targetImage;   int i = 0;   Database database = new Database(this);   String i1;   String img;   @Override  public void onCreate(Bundle savedInstanceState) {    super.onCreate(savedInstanceState);    setContentView(R.layout.main5);    buttonLoadImage = (Button) findViewById(R.id.loadimage);    targetImage = (ImageView) findViewById(R.id.targetimage);    Bundle b = getIntent().getExtras();    if (b != null) {     img = b.getString("image");     targetImage2.setImageURI("image");     //i am getting error as i cant assign string to imageview.    }    buttonLoadImage.setOnClickListener(new Button.OnClickListener() {     public void onClick(View arg0) {      // TODO Auto-generated method stub      Intent intent = new Intent(Intent.ACTION_PICK,       android.provider.MediaStore.Images.Media.EXTERNAL_CONTENT_URI);      Log.i("photo", "" + intent);      startActivityForResult(intent, i);      i = i + 1;     }    });   }    }   }  }
查看完整描述

3 回答

?
幕布斯7119047

TA貢獻(xiàn)1794條經(jīng)驗(yàn) 獲得超8個(gè)贊

你必須使用“BLOB”來存儲圖像。

示例:將圖像存儲到db:

public void insertImg(int id , Bitmap img ) {   


    byte[] data = getBitmapAsByteArray(img); // this is a function

    insertStatement_logo.bindLong(1, id);       
    insertStatement_logo.bindBlob(2, data);

    insertStatement_logo.executeInsert();
    insertStatement_logo.clearBindings() ;}

 public static byte[] getBitmapAsByteArray(Bitmap bitmap) {
    ByteArrayOutputStream outputStream = new ByteArrayOutputStream();
    bitmap.compress(CompressFormat.PNG, 0, outputStream);       
    return outputStream.toByteArray();}

要從db檢索圖像:

public Bitmap getImage(int i){

    String qu = "select img  from table where feedid=" + i ;
    Cursor cur = db.rawQuery(qu, null);

    if (cur.moveToFirst()){
        byte[] imgByte = cur.getBlob(0);
        cur.close();
        return BitmapFactory.decodeByteArray(imgByte, 0, imgByte.length);
    }
    if (cur != null && !cur.isClosed()) {
        cur.close();
    }       

    return null;}


查看完整回答
反對 回復(fù) 2019-06-20
  • 3 回答
  • 0 關(guān)注
  • 2055 瀏覽

添加回答

舉報(bào)

0/150
提交
取消
微信客服

購課補(bǔ)貼
聯(lián)系客服咨詢優(yōu)惠詳情

幫助反饋 APP下載

慕課網(wǎng)APP
您的移動(dòng)學(xué)習(xí)伙伴

公眾號

掃描二維碼
關(guān)注慕課網(wǎng)微信公眾號