zoukankan      html  css  js  c++  java
  • 每日总结

    1.今天学习sqlite的二进制文件的存取

    ①在创建数据库表的时候,需要创建一个BLOB的宇段,用于存储二进制的值

    db.execSQL("Create table test (_id INTEGER PRIMARY KEY AUTOINCREMENT,head_img BLOB));


    ②将图片转换为BLOB格式(这里是以ImageView为例的,如果是普通图片只需要转换成Bitmap再调用即可)
    SQLiteDatabase db = mDBService.getWritableDatabase0;得到数据库
    try {
    ByteArrayOutputStream outs = new ByteArrayOutputStream0;
    ((BitmapDrawable) imageview.getDrawable0).getBitmap0.compress(
    CompressFormat.PNG, 100,outs);//压缩为PNG格式,100表示跟原图大小一样Objectl args = new Object{outs.toByteArray0 }
    db.execsQL("INSERT INTO test(head_img) values(7)", args);outs.close0;
    db.close0;
    }catch (Exception e) {e.printStackTrace0;}
    2.读取SQLite中的图片:
    sQLiteDatabase db = mDBService.getreadableDatabase0;
    Cursor cursor = db.rawQuery("SELECT head_img FROM test",null);if(cursor != null)
    if(cursor.moveToFirst0){
    1/取出图片保存到宇节数组中
    byte img = cursor.getBlob(cursor.getColumnIndex("head_img");
    if(cursor != null)cursor.close0;
    J/将图片显示到ImageView上if(img != nulD
    ByteArrayInputStream bin = new ByteArrayInputStream(img);

  • 相关阅读:
    【NOIP 2003】 加分二叉树
    【POJ 1655】 Balancing Act
    【HDU 3613】Best Reward
    【POJ 3461】 Oulipo
    【POJ 2752】 Seek the Name, Seek the Fame
    【POJ 1961】 Period
    【POJ 2406】 Power Strings
    BZOJ3028 食物(生成函数)
    BZOJ5372 PKUSC2018神仙的游戏(NTT)
    BZOJ4836 二元运算(分治FFT)
  • 原文地址:https://www.cnblogs.com/chenghaixiang/p/14908557.html
Copyright © 2011-2022 走看看