Take screensot and save android

前端 未结 2 1655
无人及你
无人及你 2020-12-17 04:43

I\'m a very new android developer with a basic understanding of java. I\'ve undertaken a large project and I\'ve hit a problem I can seem to fix.

Basically my proble

2条回答
  •  情话喂你
    2020-12-17 05:14

    Hey You Can just use the below Code to capture screen shoot in android and save it in ur SDCard and then you can use it later

    // image naming and path  to include sd card  appending name you choose for file
    String mPath = Environment.getExternalStorageDirectory().toString() + "/" + ACCUWX.IMAGE_APPEND;   
    
    // create bitmap screen capture
    Bitmap bitmap;
    View v1 = mCurrentUrlMask.getRootView();
    v1.setDrawingCacheEnabled(true);
    bitmap = Bitmap.createBitmap(v1.getDrawingCache());
    v1.setDrawingCacheEnabled(false);
    
    OutputStream fout = null;
    imageFile = new File(mPath);
    
    try {
        fout = new FileOutputStream(imageFile);
        bitmap.compress(Bitmap.CompressFormat.JPEG, 90, fout);
        fout.flush();
        fout.close();
    
    } catch (FileNotFoundException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    } catch (IOException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    }
    

    Then, when you need to access use something like this:

    Uri uri = Uri.fromFile(new File(mPath));
    

提交回复
热议问题