日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 编程资源 > 编程问答 >内容正文

编程问答

android如何使用代码截屏,android实现截屏功能代码

發布時間:2023/12/20 编程问答 24 豆豆
生活随笔 收集整理的這篇文章主要介紹了 android如何使用代码截屏,android实现截屏功能代码 小編覺得挺不錯的,現在分享給大家,幫大家做個參考.

搜索熱詞

下面是編程之家 jb51.cc 通過網絡收集整理的代碼片段。

編程之家小編現在分享給大家,也給大家做個參考。

2. 添加1個Button(activity_main.xml文件)

xmlns:tools="http://schemas.android.com/tools"

android:layout_width="match_parent"

android:layout_height="match_parent"

tools:context=".MainActivity" >

android:layout_width="wrap_content"

android:layout_height="wrap_content"

android:layout_centerHorizontal="true"

android:layout_centerVertical="true"

android:text="@string/hello_world" />

android:id="@+id/btn_save"

android:layout_width="wrap_content"

android:layout_height="wrap_content"

android:text="Screenshot"

/>

3. 實現截屏(MainActivity.java文件)

package com.example.androidtest;

import java.io.File;

import java.io.FileOutputStream;

import android.os.Bundle;

import android.os.Environment;

import android.app.Activity;

import android.graphics.Bitmap;

import android.view.Menu;

import android.view.View;

import android.widget.Button;

public class MainActivity extends Activity {

@Override

protected void onCreate(Bundle savedInstanceState) {

super.onCreate(savedInstanceState);

setContentView(R.layout.activity_main);

Button btn = (Button) this.findViewById(R.id.btn_save);

btn.setOnClickListener(new View.OnClickListener() {

@Override

public void onClick(View v) {

screenshot();

}

});

}

private void screenshot()

{

// 獲取屏幕

View dView = getWindow().getDecorView();

dView.setDrawingCacheEnabled(true);

dView.buildDrawingCache();

Bitmap bmp = dView.getDrawingCache();

if (bmp != null)

{

try {

// 獲取內置SD卡路徑

String sdCardPath = Environment.getExternalStorageDirectory().getPath();

// 圖片文件路徑

String filePath = sdCardPath + File.separator + "screenshot.png";

File file = new File(filePath);

FileOutputStream os = new FileOutputStream(file);

bmp.compress(Bitmap.CompressFormat.PNG,100,os);

os.flush();

os.close();

} catch (Exception e) {

}

}

}

@Override

public boolean onCreateOptionsMenu(Menu menu) {

// Inflate the menu; this adds items to the action bar if it is present.

getMenuInflater().inflate(R.menu.activity_main,menu);

return true;

}

}

以上是編程之家(jb51.cc)為你收集整理的全部代碼內容,希望文章能夠幫你解決所遇到的程序開發問題。

如果覺得編程之家網站內容還不錯,歡迎將編程之家網站推薦給程序員好友。

總結

以上是編程之家為你收集整理的android實現截屏功能代碼全部內容,希望文章能夠幫你解決android實現截屏功能代碼所遇到的程序開發問題。

如果覺得編程之家網站內容還不錯,歡迎將編程之家網站推薦給程序員好友。

本圖文內容來源于網友網絡收集整理提供,作為學習參考使用,版權屬于原作者。

總結

以上是生活随笔為你收集整理的android如何使用代码截屏,android实现截屏功能代码的全部內容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。