资源简介
测试成功,自己下载使用,支持Android7.1.1测试成功,自己下载使用,支持Android7.1.1
代码片段和文件信息
package com.example.xiaobai.mycapture;
import android.content.Context;
import android.content.Intent;
import android.graphics.Bitmap;
import android.graphics.PixelFormat;
import android.hardware.display.DisplayManager;
import android.hardware.display.VirtualDisplay;
import android.media.Image;
import android.media.ImageReader;
import android.media.projection.MediaProjection;
import android.net.Uri;
import android.os.Environment;
import android.util.DisplayMetrics;
import android.view.WindowManager;
import android.widget.Toast;
import java.io.File;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.IOException;
import java.nio.ByteBuffer;
import static android.content.Context.WINDOW_SERVICE;
/**
* Created by Administrator on 2017/3/16.
*/
public class CreateBitmap {
private static MediaProjection mediaProjection = MyApplication.mediaProjection;
private static ImageReader mImageReader;
private static VirtualDisplay virtualDisplay1;
private static DisplayMetrics displayMetrics = new DisplayMetrics();
private static WindowManager windowManager;
private static Bitmap bmp bitmap;
private static Image image;
private static int width;
private static int height;
private static int pixelStride;
private static int rowStride;
private static int rowPadding;
private static String path name;
private static int screenwidth screenheight;
private static Image.Plane[] planes;
static ByteBuffer buffer;
private static class singleHolder {
static final CreateBitmap createbitmap = new CreateBitmap();
}
public static CreateBitmap getInstance(final Context context final Boolean isSave String inpath String inname) {
init(context inpath inname);
if (image != null) {
analysesImage();
long time = System.currentTimeMillis() - MyApplication.time;
Toast.makeText(context “截图已生成“ + time Toast.LENGTH_SHORT).show();
if (isSave)
savePic(context);
}
return singleHolder.createbitmap;
}
private static void loop() {
do {
try {
Thread.sleep(10);
} catch (InterruptedException e) {
e.printStackTrace();
}
} while (image != null);
}
// 初始化操作
private static void init(final Context context String inpath String inname) {
if (bitmap != null) {
bitmap = null;
}
path = inpath;
name = inname;
windowManager = (WindowManager) context.getSystemService(WINDOW_SERVICE);
windowManager.getDefaultDisplay().getMetrics(displayMetrics);
screenwidth = displayMetrics.widthPixels;
screenheight = displayMetrics.heightPixels;
mImageReader = ImageReader.newInstance(screenwidth screenheight PixelFormat.RGBA_8888 2);
virtualDisplay1 = mediaProjection.createVirtualDisplay(“screen-mirro
属性 大小 日期 时间 名称
----------- --------- ---------- ----- ----
文件 5576 2018-07-03 14:35 截屏\CreateBitmap.java
文件 3534 2018-07-03 14:46 截屏\MainActivity.java
文件 338 2018-07-03 14:35 截屏\MyApplication.java
文件 7203 2018-07-03 14:46 截屏\ScreenShotActivity.java
文件 723 2018-07-03 14:35 截屏\ShotClass.java
目录 0 2018-07-03 14:59 截屏
----------- --------- ---------- ----- ----
17374 6
评论
共有 条评论