以编程方式在android中截取屏幕截图的问题 [英] problem in taking screenshots in android by programmatically

查看:99
本文介绍了以编程方式在android中截取屏幕截图的问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在我的应用中,我正在获取当前屏幕的屏幕截图并将其保存在sdcard中.但在这种情况下,屏幕截图未保存在sdcard中.如何拍摄屏幕快照以及如何将捕获的屏幕快照作为附件发送到电子邮件中.请帮助我.

in my app i am taking screenshot of the current screen and save it in sdcard. but in the case screenshot is not saved in sdcard. how to take screen shot and send the captured screen shot in email as attachment. please help me.

我的编码:

            View v1 = view.getRootView();
            v1.setDrawingCacheEnabled(true);
            Bitmap bm = v1.getDrawingCache();
            try 
            {
                   System.out.println("path "+Environment.getExternalStorageDirectory());
                   FileOutputStream out = new FileOutputStream(Environment.getExternalStorageDirectory()+"/ff");
                   bm.compress(CompressFormat.PNG, 90, out);
            }
            catch (Exception e) 
            {
                   e.printStackTrace();
            }

            Intent emailIntent = new Intent(Intent.ACTION_SEND); 
            Uri U=Uri.parse("file:///sdcard/ff");
            emailIntent.putExtra(Intent.EXTRA_EMAIL, new String[] { "aabc@gmail.com" });
            emailIntent.putExtra(android.content.Intent.EXTRA_SUBJECT, " from ..");
            emailIntent.putExtra(android.content.Intent.EXTRA_TEXT, "from the app");
            emailIntent.setType("image/png");
//          emailIntent.putExtra(android.content.Intent.EXTRA_STREAM,U);
            emailIntent.putExtra(Intent.EXTRA_STREAM, U);
            startActivity(Intent.createChooser(emailIntent, "")); 

请帮助我.

推荐答案

我通过用

            File file = new File(Environment.getExternalStorageDirectory()+"/filmfestival.png");
            try 
            {
                file.createNewFile();
                FileOutputStream ostream = new FileOutputStream(file);
                bitmap.compress(CompressFormat.PNG, 100, ostream);
                ostream.close();
            } 
            catch (Exception e) 
            {
                e.printStackTrace();
            }

这篇关于以编程方式在android中截取屏幕截图的问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆