主にRPA、Androidアプリ開発について投稿しています。メモ書きです。
[PR]上記の広告は3ヶ月以上新規記事投稿のないブログに表示されています。新しい記事を書く事で広告が消えます。
public File getFileFromSD(String path){File ⇒ Bitmap
File file;
String sdPath = getExternalStorageDirectories()[0];
file = new File(sdPath + path);
if(file != null && file.exists()){
return file;
}
return null;
}
File srcFile = new File(target);Bitmap ⇒ byte[]
FileInputStream fis = new FileInputStream(srcFile);
Bitmap bm = BitmapFactory.decodeStream(fis);
public byte[] getBytes(Bitmap bitmap) {byte[] > SQLiteDatabase.blob
ByteArrayOutputStream stream = new ByteArrayOutputStream();
bitmap.compress(Bitmap.CompressFormat.PNG, 0, stream);
return stream.toByteArray();
}
cursor.getBlob(0);byte[] ⇒ String
byte[] b = c.getBlob(i);String ⇒ byte[]
strs[i] = b.toString();
public Bitmap getImage(byte[] image) {Bitmap > ImageView
return BitmapFactory.decodeByteArray(image, 0, image.length);
}
imgGenba.setImageBitmap(bmImg);
/**
* SQLiteに登録されているTBL名を取得する
* @return
*/
private ArrayList<String> getTblNames() {
ArrayList<String> tblNames = new ArrayList<>();
Cursor cursor = db.rawQuery("select name from sqlite_master where type = 'table'",null);
if(cursor.getCount() != 0){
cursor.moveToFirst();
while(cursor.moveToNext()) {
tblNames.add(cursor.getString(0));//テーブル名を保存
}
}
return tblNames;
}
/**
* テーブル名でカラム一覧を取得する
* @param tblName テーブル名
* @return カラム名一覧
*/
private ArrayList<String> getColumnNames(String tblName){
ArrayList<String> listColumn = new ArrayList<>();
Cursor cursor = db.rawQuery("PRAGMA TABLE_INFO(" + tblName+")",null);
if(cursor.getCount() != 0){
//getString(columnIndex)で取得できるもの
//0:cid、1:name、2:type、3:notnull、4:dflt_value、5:pk
cursor.moveToFirst();
while (cursor.moveToNext()){
listColumn.add(cursor.getString(1));//カラム名は1
}
}
return listColumn;
}