android studio如何更改捕获图片的存储位置

时间:2016-09-10 15:53:09

标签: android storage screenshot preview

我想知道如何更改捕获图片的存储位置。 在我的代码中,捕获的图片意味着截图图像

变量SendingImage获取Bitmap,然后我想在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);

如果有预览截图的话,请告诉我!!

谢谢:)

1 个答案:

答案 0 :(得分:0)

  

我想知道如何更改捕获图片的存储位置

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

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

欢迎您将该代码更改为符合您需求的其他代码。

  

如果有方法可以预览截图

使用an image-loading library(例如Picasso)将图片加载到ImageView