二次采样与数据的操作
二次采样
第一次采边框并且计算缩放比例,第二次采样像素
步骤:
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"));
}