Save the image made by user in fingerPaint api demos in android

前端 未结 3 457
情歌与酒
情歌与酒 2020-12-18 17:33

Hey guys I am trying to build a signature task application . In which the user will create the signature on touch and that bitmap should be saved in the phone. I have create

3条回答
  •  轮回少年
    2020-12-18 18:21

    Here is the source code to do that

    LinearLayout v = (LinearLayout) findViewById(R.id.mainLayout);
    v.setDrawingCacheEnabled(true);
    // this is the important code :)
    // Without it the view will have a
    // dimension of 0,0 and the bitmap will
    // be null
    v.measure(MeasureSpec.makeMeasureSpec(0, MeasureSpec.UNSPECIFIED), MeasureSpec.makeMeasureSpec(0, MeasureSpec.UNSPECIFIED));
    v.layout(0, 0, v.getWidth(), v.getHeight());
    v.buildDrawingCache(true);
    Bitmap bm = Bitmap.createBitmap(v.getDrawingCache());
    v.setDrawingCacheEnabled(false);
    if (bm != null) {
        try {
            String path = Environment.getExternalStorageDirectory().toString();
            OutputStream fOut = null;
            File file = new File(path, "screentest.jpg");
            fOut = new FileOutputStream(file);
            bm.compress(Bitmap.CompressFormat.JPEG, 85, fOut);
            fOut.flush();
            fOut.close();
            Log.e("ImagePath", "Image Path : " + MediaStore.Images.Media.insertImage( getContentResolver(), file.getAbsolutePath(), file.getName(), file.getName()));
        }
        catch (Exception e) {
            e.printStackTrace();
        }
    }
    

    Hope this will work with you also.

提交回复
热议问题