我正在开发一个应用程序,我想拍摄当前屏幕的屏幕截图,但没有标题栏.我知道捕获ScreenShot的代码,但无法自定义它.
码:
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);
}
});
Run Code Online (Sandbox Code Playgroud)
当我点击它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>
Run Code Online (Sandbox Code Playgroud)
捕获屏幕截图前的图像..

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

将其带到另一个线性布局
<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>
Run Code Online (Sandbox Code Playgroud)
现在在oncreate()方法上找到此线性布局的Id,使其成为全局变量
LinearLayout ll;
ll = (LinearLayout)findViewById(R.id.linear);
Run Code Online (Sandbox Code Playgroud)
现在抓住这个屏幕
ll.setDrawingCacheEnabled(true);
ll.buildDrawingCache(true);
Bitmap cs = Bitmap.createBitmap(ll.getDrawingCache());
ll.setDrawingCacheEnabled(false);
Run Code Online (Sandbox Code Playgroud)
现在将此位图设置为ImageView.
| 归档时间: |
|
| 查看次数: |
7481 次 |
| 最近记录: |