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);

  • 相关阅读:
    python
    python
    gitlab
    nodejs
    java
    ElasticSearch 安装与配置 (windows)
    shell脚本批量注释
    C获取系统中CPU核数
    linux内核内存管理
    perf: interrupt took too long (3136 > 3126), lowering kernel.perf_event_max_sample_rate to 63000
  • 原文地址:https://www.cnblogs.com/chenghaixiang/p/14908557.html
Copyright © 2011-2022 走看看