android studio如何更改截取图片的存储位置

android studio how to change storage location of captured picture

我想知道如何更改拍摄图片的存储位置。 在我的代码中,捕获的图片表示屏幕截图图像

变量SendingImage获取位图,然后我想将截图存储在sdcard或其他地方。 存储后,我想通过 String

获取关于屏幕截图位置的 Uri

这是我的代码=

 File sdCard = Environment.getExternalStorageDirectory();


    String filename = "screenshot1.jpg";

    ImageView GetImage = (ImageView) findViewById(R.id.show_heyboard);

    GetImage.setDrawingCacheEnabled(true);

    Bitmap SendingImage;

    GetImage.buildDrawingCache();

    SendingImage = GetImage.getDrawingCache();

    Toast.makeText(getApplicationContext(), "1_is working", Toast.LENGTH_SHORT).show();


    try{
        File files = new File(sdCard.getAbsolutePath()+"/sdcard");
        files.mkdirs();
        File f = new File(files, "screaanshot1");
        FileOutputStream outStream = new FileOutputStream(f);
        SendingImage.compress(Bitmap.CompressFormat.PNG, 100, outStream);

        outStream.close();
    } catch(IOException e){
        e.printStackTrace();
    }

    GetImage.setDrawingCacheEnabled(false);

如果有办法预览截图,请告诉我!!

谢谢:)

I want to know how to change storage location of captured picture

您编写了指定存储位置的代码:

File files = new File(sdCard.getAbsolutePath()+"/sdcard");
files.mkdirs();
File f = new File(files, "screaanshot1");

欢迎您将该代码更改为适合您需要的其他内容。

If there is way to get preview of screenshot

使用 an image-loading library, like Picasso,将您的图像加载到 ImageView