- r - 以节省内存的方式增长 data.frame
- ruby-on-rails - ruby/ruby on rails 内存泄漏检测
- android - 无法解析导入android.support.v7.app
- UNIX 域套接字与共享内存(映射文件)
首先,我正在编写一个根应用程序,因此根权限没有问题。我已经搜索和搜索,发现很多对我来说从来没有用过的代码是我迄今为止拼凑起来的,并且有点工作。当我说 sorta 时,我的意思是它在我的/sdcard/test.png 上制作了一张图片,但是该文件为 0 字节,显然无法查看。
public class ScreenShot extends Activity{
View content;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.blank);
content = findViewById(R.id.blankview);
getScreen();
}
private void getScreen(){
Bitmap bitmap = content.getDrawingCache();
File file = new File("/sdcard/test.png");
try
{
file.createNewFile();
FileOutputStream ostream = new FileOutputStream(file);
bitmap.compress(CompressFormat.PNG, 100, ostream);
ostream.close();
}
catch (Exception e)
{
e.printStackTrace();
}
}
}
任何关于我如何通过代码在 android 中截屏的帮助将不胜感激,谢谢!
===编辑===
以下是我正在使用的所有内容图像是在我的 sdcard 上制作的,不再是 0bytes,但整个东西都是黑色的,上面什么都没有。我已经将 Activity 绑定(bind)到我的搜索按钮,所以当我在手机上的某个位置时,我长按搜索,它应该截屏但我只是得到一个黑色图像?一切都设置为透明,所以我认为它应该捕获屏幕上的任何东西,但我只是不断变黑
list
<activity android:name=".extras.ScreenShot"
android:theme="@android:style/Theme.Translucent.NoTitleBar"
android:noHistory="true" >
<intent-filter>
<action android:name="android.intent.action.SEARCH_LONG_PRESS" />
<category android:name="android.intent.category.DEFAULT" />
</intent-filter>
</activity>
XML
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#00000000"
android:id="@+id/screenRoot">
</LinearLayout>
截图类
public class ScreenShot extends Activity{
View content;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.screenshot);
content = findViewById(R.id.screenRoot);
ViewTreeObserver vto = content.getViewTreeObserver();
vto.addOnGlobalLayoutListener(new OnGlobalLayoutListener() {
@Override
public void onGlobalLayout() {
content.getViewTreeObserver().removeGlobalOnLayoutListener(this);
getScreen();
}
});
}
private void getScreen(){
View view = content;
View v = view.getRootView();
v.setDrawingCacheEnabled(true);
Bitmap b = v.getDrawingCache();
String extr = Environment.getExternalStorageDirectory().toString();
File myPath = new File(extr, "test.jpg");
FileOutputStream fos = null;
try {
fos = new FileOutputStream(myPath);
b.compress(Bitmap.CompressFormat.JPEG, 100, fos);
fos.flush();
fos.close();
MediaStore.Images.Media.insertImage(getContentResolver(), b, "Screen", "screen");
}catch (FileNotFoundException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (Exception e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
finish();
}
}
最佳答案
给你...我用这个:
View v = view.getRootView();
v.setDrawingCacheEnabled(true);
Bitmap b = v.getDrawingCache();
String extr = Environment.getExternalStorageDirectory().toString();
File myPath = new File(extr, getString(R.string.free_tiket)+".jpg");
FileOutputStream fos = null;
try {
fos = new FileOutputStream(myPath);
b.compress(Bitmap.CompressFormat.JPEG, 100, fos);
fos.flush();
fos.close();
MediaStore.Images.Media.insertImage( getContentResolver(), b,
"Screen", "screen");
} catch (FileNotFoundException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (Exception e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
v iz 根布局...只是指出 ;)))
关于Android以编程方式截屏,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7762643/
我需要截屏并保存截屏。我需要在不使用与 PC 的任何连接或不取消手机根目录的情况下执行此操作。每当触发事件时,我都需要这样做。例如,当游戏中显示广告时......或者当游戏结束并显示蛇的分数等时。你能
我正在尝试捕捉(屏幕截图) View 。为此,我使用下面显示的一段代码将其作为 PNG 图像保存到我的文档目录中。 UIGraphicsBeginImageContextWithOptions(hig
本文实例总结了常见的java编程实现屏幕截图方法。分享给大家供大家参考,具体如下: 方法一: ?
关闭。这个问题不符合Stack Overflow guidelines .它目前不接受答案。 我们不允许在 Stack Overflow 上提出有关通用计算硬件和软件的问题。您可以编辑问题,使其成为
我正在构建一个跨平台桌面应用程序。我正在使用 electronjs 框架开发我的桌面应用程序。我想在我的应用程序启动时添加每 5 分钟截取一次屏幕截图的功能! 帮助将不胜感激我的 main.js //
我从另一个包导入这个类并尝试调用这个方法,但它不起作用。 当我在同一个类中创建此方法并调用它时,它正在工作。 private void getScreenshot() throws IOExcept
我正在尝试截取增强现实屏幕的屏幕截图并将其作为位图传递给另一个 Activity 。 这是我用来截取屏幕截图的代码: 截屏功能 public static void tmpScreenshot(Bit
我有一个绘图区,我在里面画了一些图形或图像,所以我有这个回调来截屏: void CanvasToolBox::actionCanvasCamera() { auto root = Gdk::W
我正在使用 AVCaptureMetadataOutput 以使用 iOS QRCode、条形码扫描功能。这很好用,我得到了通过 AVCaptureMetadataOutput 委托(delegate
我想截取我 View 中特定部分的屏幕截图(具体来说是 ImageView ),是否有机会.... 最佳答案 看来您需要执行 renderInContext。 // Size of the resul
这个问题在这里已经有了答案: Read binary stdout data like screencap data from adb shell? (19 个回答) 关闭5年前. 我正在尝试尽快获取
嘿,我正在使用 WEBRTC 进行屏幕共享。但是我被困在我需要用户整个屏幕的地方,但是浏览器为用户提供了更多选项,例如应用程序和浏览器选项卡,所以我想检查用户从浏览器产生的弹出窗口中选择的选项,如果它
我正在压力测试中测试应用程序。 这就是为什么我需要它在发生错误(错误窗口打开)或挂起或崩溃时重新启动。同时,我需要收集有关导致重启的问题的所有有用信息:制作转储文件,并从错误窗口复制错误文本(和/或获
按照目前的情况,这个问题不适合我们的问答形式。我们希望答案得到事实、引用或专业知识的支持,但这个问题可能会引发辩论、争论、投票或扩展讨论。如果您觉得这个问题可以改进并可能重新打开,visit the
嗨,这里有人可以帮助我使用 phantomJS 截取我的 div 吗?我如何截取我的 #dropzone 然后将其附加到同一页面? 请帮忙。 最佳答案 有两种方法可以部分呈现网页。 1) 只用 div
这是我写的用于保存网页截图的简单python代码。 from selenium import webdriver import time driver=webdriver.Firefox() driv
出于安全原因,我当前正在构建的应用程序要求应用程序必须阻止操作系统在应用程序被插入后台时截取该应用程序的屏幕截图。这样在应用之间切换时将无法看到最后一个 Activity 屏幕。 我打算将此功能放在应
我正在尝试从 Silverlight 5 应用程序中截取子类 XNA DrawingSurface 元素的屏幕截图。这个 sl 应用程序将在一个 aspx 页面内运行。 这是我迄今为止尝试过但没有成功
我正在使用 Xcode 构建 iPhone/iPad 应用程序。 现在我想截取这个应用程序的屏幕截图。 尺寸为 960x640。 那怎么办? 模拟器屏幕太小 最佳答案 您可以使用 cmd+S进入模拟器
我找到了一些代码示例,但我不知道哪些 JNA 版本可以使用哪些方法。我只找到了一些片段,其中缺少类,而且我无法导入它们。 我想知道我应该使用哪个 JNA 版本以及如何获取 BufferedImage
我是一名优秀的程序员,十分优秀!