gpt4 book ai didi

Android - 以编程方式捕获没有标题栏的屏幕截图

转载 作者:太空狗 更新时间:2023-10-29 15:53:34 24 4
gpt4 key购买 nike

我正在开发一个应用程序,因为我想截取当前屏幕的屏幕截图但没有标题栏。我知道捕获屏幕截图的代码,但无法对其进行自定义。

代码:

munchscreen.setOnClickListener(new OnClickListener() {

@Override
public void onClick(View v) {
View v1 = L1.getRootView();
v1.setDrawingCacheEnabled(true);
Bitmap bm = v1.getDrawingCache();
BitmapDrawable bitmapDrawable = new BitmapDrawable(bm);
image = (ImageView) findViewById(R.id.screenshots);
image.setBackgroundDrawable(bitmapDrawable);
}
});

当我点击 Clip 时,它应该会截取下面显示的屏幕截图,但不应该包括我圈出的部分。

XML:

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#D8D5AA"
>


<LinearLayout
android:id="@+id/clip_from_web_linearlayout1"
android:layout_width="match_parent"
android:layout_height="50dp"
android:background="@drawable/header"
android:orientation="horizontal"
>
<TextView
android:id="@+id/clip_from_web_textview_back"
android:layout_height="wrap_content"
android:layout_width="wrap_content"
android:text="Back"
android:layout_gravity="center"
android:layout_marginLeft="5dp"
android:textColor="#FFFFFF"
android:textSize="18sp"
/>

<TextView
android:id="@+id/clip_from_web_textview_header_title"
android:layout_height="wrap_content"
android:layout_width="wrap_content"
android:text="Clip From Web"
android:layout_gravity="center"
android:layout_marginLeft="60dp"
android:textColor="#FFFFFF"
android:textSize="18sp"
/>

<TextView
android:id="@+id/clip_from_web_textview_clip"
android:layout_height="wrap_content"
android:layout_width="wrap_content"
android:text="Clip"
android:layout_gravity="center"
android:layout_marginLeft="60dp"
android:textColor="#FFFFFF"
android:textSize="18sp"
/>

</LinearLayout>


<Button
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="@string/munch"
android:id="@+id/munchscreen"
android:layout_below="@+id/clip_from_web_linearlayout1"
/>
<ImageView
android:layout_width="200dp"
android:layout_height="200dp"
android:id="@+id/screenshots"
android:layout_below="@+id/munchscreen"
android:contentDescription="@string/app_name"
android:layout_centerInParent="true"

/>

<RelativeLayout
android:id="@+id/clip_from_web_bottom_bar"
android:layout_width="match_parent"
android:layout_height="50dp"
android:layout_alignParentBottom="true"
android:background="@drawable/header" >

<Button
android:id="@+id/clip_from_web_previous"
android:layout_width="40dp"
android:layout_height="40dp"
android:layout_marginLeft="4dp"
android:background="@android:drawable/ic_media_previous"
android:layout_marginTop="2dp"
/>

<Button
android:id="@+id/clip_from_web_reload"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerHorizontal="true"
android:background="@android:drawable/ic_menu_rotate"
android:layout_marginTop="5dp"
/>

<Button
android:id="@+id/clip_from_web_next"
android:layout_width="40dp"
android:layout_height="40dp"
android:layout_toRightOf="@+id/clip_from_web_reload"
android:layout_marginLeft="102dp"
android:background="@android:drawable/ic_media_next"
android:layout_marginTop="2dp"
/>

</RelativeLayout>

捕获屏幕截图之前的图像..

enter image description here

捕获屏幕截图后的图像..

enter image description here

最佳答案

把这个带到另一个线性布局

  <LinearLayout 
android:id="@+id/linear"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">

<Button
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="@string/munch"
android:id="@+id/munchscreen"

/>
<ImageView
android:layout_width="200dp"
android:layout_height="200dp"
android:id="@+id/screenshots"
android:contentDescription="@string/app_name"
/>
</LinearLayout>

现在在 oncreate() 方法上找到这个线性布局的 Id,使其成为全局变量

 LinearLayout ll;

ll = (LinearLayout)findViewById(R.id.linear);

现在捕获这个屏幕

 ll.setDrawingCacheEnabled(true);
ll.buildDrawingCache(true);
Bitmap cs = Bitmap.createBitmap(ll.getDrawingCache());
ll.setDrawingCacheEnabled(false);

现在将此位图设置到您的 ImageView。

关于Android - 以编程方式捕获没有标题栏的屏幕截图,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21228239/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com