/**
* 判断是否在当前主线程
* @return
*/
public static boolean isOnMainThread(){
return Thread.currentThread() == Looper.getMainLooper().getThread();
}
、、、、、、、、、、、、、、、、、、、、、、、、、、、、、、、、、、、、、
/*
* 将时间戳转换为时间
*/publicstatic String stampToDate(String s){
String res;
SimpleDateFormat simpleDateFormat =newSimpleDateFormat("yyyy-MM-dd HH:mm:ss");
longlt =new Long(s);
Date date =new Date(lt);
res = simpleDateFormat.format(date);
return res;
}
//图片保存
public void saveBitmap(Bitmap b) {
//设置路径(SD卡位置+"/OpenGL_VIP/photo/")
String path = Environment.getExternalStorageDirectory().getAbsolutePath() + "/OpenGL_VIP/photo/";
File folder = new File(path);
if (!folder.exists() && !folder.mkdirs()) {
runOnUiThread(new Runnable() {
@Override
public void run() {
Toast.makeText(Camera2Activity.this, "无法保存照片", Toast.LENGTH_SHORT).show();
}
});
return;
}
long dataTake = System.currentTimeMillis();
final String jpegName = path + dataTake + ".jpg";
try {
FileOutputStream fout = new FileOutputStream(jpegName);
BufferedOutputStream bos = new BufferedOutputStream(fout);
b.compress(Bitmap.CompressFormat.JPEG, 100, bos);
bos.flush();
bos.close();
} catch (IOException e) {
e.printStackTrace();
}
runOnUiThread(new Runnable() {
@Override
public void run() {
Toast.makeText(Camera2Activity.this, "保存成功->" + jpegName, Toast.LENGTH_SHORT).show();
}
});
}
网友评论