美文网首页
一些方法收集

一些方法收集

作者: yasuion | 来源:发表于2018-06-26 15:36 被阅读0次

/**

* 判断是否在当前主线程

* @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();

            }

        });

    }

相关文章

网友评论

      本文标题:一些方法收集

      本文链接:https://www.haomeiwen.com/subject/nnkmyftx.html