Android 二次采样与数据库的增删改查

二次采样与数据的操作

二次采样

第一次采边框并且计算缩放比例,第二次采样像素

步骤:
BitmapFactory.Options option=new BitmapFactory.Options();
options.injustDecideBounds=false/true: false采像素,true 采边框

options.outwidth:拿到原图的宽
options.outheight:拿到原图的高
options.inSamplesize=suofangbili:设置缩放比例

// An highlighted block
byte[] bytes = new MyAsktask().execute("https://img.zcool.cn/community/01d366579c1d140000018c1b0da9ed.jpg@1280w_1l_2o_100sh.png").get();
            BitmapFactory.Options options=new BitmapFactory.Options();
            options.inJustDecodeBounds=true;
            BitmapFactory.decodeByteArray(bytes,0,bytes.length,options);

            int outWidth = options.outWidth;
            int outHeight = options.outHeight;
            int size=1;
            while (outWidth/size>500||outHeight/size>500){
                size*=2;
            }

            options.inJustDecodeBounds=false;
            options.inSampleSize=size;
           Bitmap bitmap = BitmapFactory.decodeByteArray(bytes,0,bytes.length,options);
           imageView.setImageBitmap(bitmap);

        } catch (ExecutionException e) {
            e.printStackTrace();
        } catch (InterruptedException e) {
            e.printStackTrace();
        }

##数据库的增、删、改、查
SQLiteOpenHelper:用来创建数据库,数据表,更行版本

用法:
继承:class MyHelper extends SQLiteOpenHelper
调用父类构造方法
重写onCreate方法
重写update方法

SqLiteDatabase
用法:
获得数据库 helper对象.getwritableDatabase();
查:rawQuery(“sql语句",new String[]{”值“})
增删改:execSQL(”sql语句")

增:insert(“表名”,“列名”,值(ContentValue))
删:delete(“表名”,“列名=?”,new String[]{“值”})
改:update(“表名”,新值(ContentValue),“条件=?”,new String[]{“值”})
查:query(“表名”,new String[]{“列名”},“条件=?”,new String[]{“值”},“分组的列名”,“having”,“排序的列名”)

ContentValue:
用法:new 对象 .put(“列名”,值)

//new 出对象

// An highlighted block

   myOpenHelper helper = new myOpenHelper(this);
         db=helper.getWritableDatabase();

//增删改

// An highlighted block

   db.execSQL("insert into test1 values(null,'李',20)"); //增、删、改

//查

// An highlighted block

   Cursor cursor =db.rawQuery("select * from test1",null);
        while (cursor.moveToNext()){
           String name =cursor.getString(cursor.getColumnIndex("name"));//cursor.getColumnName(cursor.getColumnIndex("name"));
           int id = cursor.getInt(cursor.getColumnIndex("_id"));
          int age = cursor.getInt(cursor.getColumnIndex("age"));
          }
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值