本文介绍了Android的活动截图怎么样?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

您好好友我有做网页介面应用
我想把我的活动截图
Currnetly我使用这个code捕获图像

Hello Friends i'm making a app with webviewi want to take screenshot of my activityCurrnetly i'm using this code for capture image

public Bitmap takeScreenshot() {
   View rootView = findViewById(android.R.id.content).getRootView();
   rootView.setDrawingCacheEnabled(true);
   return rootView.getDrawingCache();
}

这对于保存

public void saveBitmap(Bitmap bitmap) {
    File imagePath = new File(Environment.getExternalStorageDirectory() + "/screenshot.png");
    FileOutputStream fos;
    try {
        fos = new FileOutputStream(imagePath);
        bitmap.compress(CompressFormat.JPEG, 100, fos);
        fos.flush();
        fos.close();
    } catch (FileNotFoundException e) {
        Log.e("GREC", e.getMessage(), e);
    } catch (IOException e) {
        Log.e("GREC", e.getMessage(), e);
    }
}

这一段工程和某个不,我的意思是,有时我可以在画廊看到的截图和某个不
我想,如果有任何选项来显示捕获的屏幕截图
就像我们whhen preSS音量+电源键

It sometime Works and sometime not, i mean ,sometime i can see in gallery screenshot and sometime noti want to if there is any option to show captured screenshotLike whhen we press Vol+power button

主要的问题是我怎么能显示图像的拍摄时
或者还是知道如果不采取
在此先感谢

Main problem is how can i show image when its takenor know if its taken or not Thanks in advance

推荐答案

这是一个简单的方法:保存图片 - >与对话显示的结果。并使其在Android图库提供,文件路径也应改为:

This is a sample approach: save your image -> display result with dialog. And to make it available in Android Gallery, the file path should also be changed:

public void saveBitmap(Bitmap bitmap) {
File path = Environment.getExternalStoragePublicDirectory(
        Environment.DIRECTORY_PICTURES);
File imagePath = new File(path, "screenshot.png");//now gallery can see it
FileOutputStream fos;
 try {
     fos = new FileOutputStream(imagePath);
     bitmap.compress(CompressFormat.JPEG, 100, fos);
     fos.flush();
     fos.close();

     displayResult(imagePath.getAbsolutePath())// here you display your result after saving
 } catch (FileNotFoundException e) {
     Log.e("GREC", e.getMessage(), e);
 } catch (IOException e) {
     Log.e("GREC", e.getMessage(), e);
 }
}

创建另一个方法调用 displayResult 来查看结果:

public void displayResult(String imagePath){

    //LinearLayOut Setup
    LinearLayout linearLayout= new LinearLayout(this);
    linearLayout.setOrientation(LinearLayout.VERTICAL);

    linearLayout.setLayoutParams(new LayoutParams(
            LayoutParams.MATCH_PARENT,
            LayoutParams.MATCH_PARENT));

    //ImageView Setup
    ImageView imageView = new ImageView(this);//you need control the context of Imageview

    //Diaglog setup
    final Dialog dialog = new Dialog(this);//you need control the context of this dialog
    dialog.setContentView(imageView);

   imageView.setOnClickListener(new OnClickListener() {
            @Override
            public void onClick(View v) {
                dialog.dismiss();
            }
        });

   //Display result
   imageView.setImageBitmap(BitmapFactory.decodeFile(imagePath));
   dialog.show();

}

这篇关于Android的活动截图怎么样?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

10-15 00:45