精华内容
下载资源
问答
  • Android截图

    热门讨论 2013-09-29 15:06:03
    Android截图Android截图 可以根据已经实现的截图功能进行扩展功能:例如:摇一摇截图,开启定时截图功能
  • android截图 区域截图 部分截图
  • android_WebView截图

    千次阅读 2017-04-21 00:25:12
    WebView截图 android WebView
    //长截屏	5.0以上就行不通
    //获取Picture对象
    Picture picture = wv_capture.capturePicture();
    //得到图片的宽和高(没有reflect图片内容)
    int width = picture.getWidth();
    int height = picture.getHeight();
    if (width > 0 && height > 0) {
        //创建位图
        Bitmap bitmap = Bitmap.createBitmap(width, height, Bitmap.Config.ARGB_8888);
        Canvas canvas = new Canvas(bitmap);
        //绘制(会调用native方法,完成图形绘制)
        picture.draw(canvas);
    
    }
    
    
    
    
    //5.0建议的方法
    //只显示了webview	
    enableSlowWholeDocumentDraw(),在setContentView前去调用
    //获取webview缩放率
    float scale = wv_capture.getScale();
    //得到缩放后webview内容的高度
    int webViewHeight = (int) (wv_capture.getContentHeight()*scale);
    Bitmap bitmap = Bitmap.createBitmap(wv_capture.getWidth(),webViewHeight, Bitmap.Config.ARGB_8888);
    Canvas canvas = new Canvas(bitmap);
    //绘制
    wv_capture.draw(canvas);
    
    
    
    
    
    
     //截图下来,然后保存
         public void go() {
            Picture picture = webView.capturePicture();
            int width = picture.getWidth();
            int height = picture.getHeight();
            if (width > 0 && height > 0) {
                //创建位图
                Bitmap bitmap = Bitmap.createBitmap(width, height, Bitmap.Config.ARGB_8888);
                Canvas canvas = new Canvas(bitmap);
                //绘制(会调用native方法,完成图形绘制)
                picture.draw(canvas);
                iv.setImageBitmap(bitmap);
                Toast.makeText(this, "截屏成功" + width + "   " + height + "  " + canvas.getHeight(), Toast.LENGTH_SHORT).show();
                try {
                    String fileName = Environment.getExternalStorageDirectory().getPath() + "/webview_capture4.jpg";
                    FileOutputStream fos = new FileOutputStream(fileName);
                    //压缩bitmap到输出流中
                    bit = Bitmap.createBitmap(bitmap);
                    bit.compress(Bitmap.CompressFormat.JPEG, 70, fos);
                    fos.close();
                    Toast.makeText(this, "截屏成功", Toast.LENGTH_SHORT).show();
                } catch (Exception e) {
                } finally {
                    if (bit != null) {
                        bit.recycle();
                    }
    
                }
            }
        }
    
    
    
    
    
    
    
    
    //在Activity销毁时进行回收,所以开启缓存的话会有性能开销
    webView.setDrawingCacheEnabled(true);
    ...
    Bitmap bitmap = webView.getDrawingCache();
    //多次调用会崩溃,so
    public void go2() {
        Bitmap bitmap;
        if (webView.isDrawingCacheEnabled()) {
            webView.buildDrawingCache();
            bitmap = webView.getDrawingCache();
        } else {
            webView.setDrawingCacheEnabled(true);
            bitmap = webView.getDrawingCache();
        }
        Bitmap bit = Bitmap.createBitmap(bitmap);
        iv.setImageBitmap(bit);
        webView.destroyDrawingCache();
    }
    
    
    
    
    
    
    //整个窗口的截图
    View view = context.getWindow().getDecorView();
    Bitmap bitmap = Bitmap.createBitmap(view.getWidth(), view.getHeight(), Bitmap.Config.ARGB_8888);
    Canvas canvas = new Canvas(bitmap);view.draw(canvas);
    //保存
     saveFiletry { String fileName = Environment.getExternalStorageDirectory().getPath()+"/webview_capture4.jpg"; 
    FileOutputStream fos = new FileOutputStream(fileName); 
    //压缩bitmap到输出流中 
    bitmap.compress(Bitmap.CompressFormat.JPEG, 70, fos); fos.close(); 
    Toast.makeText(WebviewFromGetDecorView.this, "截屏成功", Toast.LENGTH_LONG).show(); 
    } catch (Exception e) 
    { Log.e(TAG, e.getMessage()); 
    }
    finally 
    { if(bitmap!=null)
     { bitmap.recycle();
     } }
    
    
    
    
    
    
    
    
    
    
    
    
    展开全文
  • android截图

    2014-01-08 01:16:59
    android 页面截图,非常好的下载资料
  • Android反射系统截图Api

    2021-02-20 13:56:51
    通过Java反射系统的方式去截图Android截图Api踩坑点附上详细代码执行操作 Android截图Api Android5.0以下:android.view.Surface Android5.0以上:android.view.SurfaceControl 踩坑点 在Android 10以上系统更新...

    通过Java反射系统的方式去截图

    Android截图Api

    Android5.0以下:android.view.Surface
    Android5.0以上:android.view.SurfaceControl
    

    踩坑点

    在Android 10以上系统更新调用方法,所以需要区分,如下:

    if (Build.VERSION.SDK_INT <= 28) {
     	method = Class.forName(surfaceClassName).getDeclaredMethod("screenshot", new Class[]{Integer.TYPE, Integer.TYPE});
    	bitmap = (Bitmap) method.invoke(null, new Object[]{sizes[0], sizes[1]});
    } else {//android Q 以上支持
    	method = Class.forName(surfaceClassName).getDeclaredMethod("screenshot", new Class[]{Rect.class, int.class, int.class, int.class});
    	Rect rect = new Rect();
    	rect.left = 0;
    	rect.top = 0;
    	bitmap = (Bitmap) method.invoke(null, new Object[]{rect, sizes[0], sizes[1], sizes[2]});
    }
    

    附上详细代码

    package com.lyyd.screenshot
    
    import android.annotation.TargetApi;
    import android.content.Context;
    import android.graphics.Bitmap;
    import android.graphics.Rect;
    import android.os.Build;
    import android.os.IBinder;
    import android.os.IInterface;
    
    import java.io.File;
    import java.io.FileNotFoundException;
    import java.io.FileOutputStream;
    import java.io.IOException;
    import java.lang.reflect.InvocationTargetException;
    import java.lang.reflect.Method;
    
    public class RunTest {
    
        public static void main(String[] args) {
            RunTest runTest = new RunTest();
            System.out.println("start screen");
            String surfaceClassName = "";
            if (Build.VERSION.SDK_INT <= 17) {
                surfaceClassName = "android.view.Surface";
            } else {
                surfaceClassName = "android.view.SurfaceControl";
            }
            try {
                Class<?> clazz = Class.forName(surfaceClassName);
                Method[] methods = clazz.getMethods();
                for (Method method : methods) {
                    System.out.println("Method Name =>" + method.toGenericString()); //输出反射类的所有调用方法信息
                }
                Method method;
                Bitmap bitmap;
                long start = System.currentTimeMillis();
                int[] sizes = runTest.getDisplaySize();
                if (Build.VERSION.SDK_INT <= 28) {
                    method = Class.forName(surfaceClassName).getDeclaredMethod("screenshot", new Class[]{Integer.TYPE, Integer.TYPE});
                    bitmap = (Bitmap) method.invoke(null, new Object[]{sizes[0], sizes[1]});
                } else {//android Q 以上支持
                    method = Class.forName(surfaceClassName).getDeclaredMethod("screenshot", new Class[]{Rect.class, int.class, int.class, int.class});
                    Rect rect = new Rect();
                    rect.left = 0;
                    rect.top = 0;
                    bitmap = (Bitmap) method.invoke(null, new Object[]{rect, sizes[0], sizes[1], sizes[2]});
                }
                runTest.saveBitmap(bitmap);
                System.out.println("截图耗时:" + (System.currentTimeMillis() - start) / 1000);
                System.out.println("shot success");
            } catch (IllegalAccessException e) {
                System.out.println("1 error");
                e.printStackTrace();
            } catch (InvocationTargetException e) {
                System.out.println("2 error");
                e.printStackTrace();
            } catch (NoSuchMethodException e) {
                System.out.println("3 error");
                e.printStackTrace();
            } catch (ClassNotFoundException e) {
                System.out.println("4 error");
                e.printStackTrace();
            }
        }
    
        public void saveBitmap(Bitmap bitmap) {
            FileOutputStream out = null;
            try {
                System.out.println("create bitmap");
                File file = new File("/sdcard/screenshot.png");
                file.createNewFile();
                out = new FileOutputStream(file);
                bitmap.compress(Bitmap.CompressFormat.PNG, 100, out);
                out.flush();
                out.close();
            } catch (FileNotFoundException e) {
                e.printStackTrace();
            } catch (IOException e) {
                e.printStackTrace();
            } finally {
                if (out != null) {
                    try {
                        out.close();
                    } catch (IOException e) {
                        e.printStackTrace();
                    }
                }
            }
        }
    
        /**
         * 反射获取屏幕分辨率
         * width
         * height
         * rotation
         * @return
         */
        @TargetApi(Build.VERSION_CODES.KITKAT)
        public int[] getDisplaySize() {
            try {
                Class clazz = Class.forName("android.os.ServiceManager");
                Method getServiceMethod = clazz.getDeclaredMethod("getService", String.class);
                IBinder binder = (IBinder) getServiceMethod.invoke(null, Context.DISPLAY_SERVICE);
                Method asInterface = Class.forName("android.hardware.display.IDisplayManager$Stub").getMethod("asInterface", IBinder.class);
                IInterface service = (IInterface) asInterface.invoke(null, binder);
                Object displayInfo = service.getClass().getMethod("getDisplayInfo", int.class).invoke(service, 0);
                Class<?> displayClass = displayInfo.getClass();
                int width = displayClass.getDeclaredField("logicalWidth").getInt(displayInfo);
                int height = displayClass.getDeclaredField("logicalHeight").getInt(displayInfo);
                int rotation = displayClass.getDeclaredField("rotation").getInt(displayInfo);
                return new int[]{width, height, rotation};
            } catch (ClassNotFoundException | NoSuchMethodException e) {
                e.printStackTrace();
            } catch (IllegalAccessException e) {
                e.printStackTrace();
            } catch (InvocationTargetException e) {
                e.printStackTrace();
            } catch (NoSuchFieldException e) {
                e.printStackTrace();
            }
            return null;
        }
    }
    
    

    执行操作

    1. 将代码打包成apk,然后push到手机端/data/local/tmp/目录即可
    2. 使用adb shell 进入手机目录
    3. 执行export CLASSPATH=/data/local/tmp/screenshot.apk
    4. 在执行 app_process /system/bin com.lyyd.screenshot.RunTest
      在这里插入图片描述
      执行成功后会输出日志信息
    start screen
    Method Name =>public static android.view.SurfaceControl$ScreenshotGraphicBuffer android.view.SurfaceControl.captureLayers(android.os.IBinder,android.graphics.Rect,float)
    Method Name =>public static android.view.SurfaceControl$ScreenshotGraphicBuffer android.view.SurfaceControl.captureLayersExcluding(android.os.IBinder,android.graphics.Rect,float,android.os.IBinder[])
    Method Name =>public static boolean android.view.SurfaceControl.clearAnimationFrameStats()
    Method Name =>public boolean android.view.SurfaceControl.clearContentFrameStats()
    Method Name =>public static void android.view.SurfaceControl.closeTransaction()
    Method Name =>public void android.view.SurfaceControl.copyFrom(android.view.SurfaceControl)
    Method Name =>public static android.os.IBinder android.view.SurfaceControl.createDisplay(java.lang.String,boolean)
    Method Name =>public void android.view.SurfaceControl.deferTransactionUntil(android.os.IBinder,long)
    Method Name =>public void android.view.SurfaceControl.deferTransactionUntil(android.view.Surface,long)
    Method Name =>public int android.view.SurfaceControl.describeContents()
    Method Name =>public static void android.view.SurfaceControl.destroyDisplay(android.os.IBinder)
    Method Name =>public void android.view.SurfaceControl.detachChildren()
    Method Name =>public void android.view.SurfaceControl.disconnect()
    Method Name =>public boolean java.lang.Object.equals(java.lang.Object)
    Method Name =>public static int android.view.SurfaceControl.getActiveColorMode(android.os.IBinder)
    Method Name =>public static int android.view.SurfaceControl.getActiveConfig(android.os.IBinder)
    Method Name =>public static int[] android.view.SurfaceControl.getAllowedDisplayConfigs(android.os.IBinder)
    Method Name =>public static boolean android.view.SurfaceControl.getAnimationFrameStats(android.view.WindowAnimationFrameStats)
    Method Name =>public final java.lang.Class<?> java.lang.Object.getClass()
    Method Name =>public static android.graphics.ColorSpace[] android.view.SurfaceControl.getCompositionColorSpaces()
    Method Name =>public boolean android.view.SurfaceControl.getContentFrameStats(android.view.WindowContentFrameStats)
    Method Name =>public static boolean android.view.SurfaceControl.getDisplayBrightnessSupport(android.os.IBinder)
    Method Name =>public static int[] android.view.SurfaceControl.getDisplayColorModes(android.os.IBinder)
    Method Name =>public static android.view.SurfaceControl$PhysicalDisplayInfo[] android.view.SurfaceControl.getDisplayConfigs(android.os.IBinder)
    Method Name =>public static android.view.SurfaceControl$DisplayPrimaries android.view.SurfaceControl.getDisplayNativePrimaries(android.os.IBinder)
    Method Name =>public static android.hardware.display.DisplayedContentSample android.view.SurfaceControl.getDisplayedContentSample(android.os.IBinder,long,long)
    Method Name =>public static android.hardware.display.DisplayedContentSamplingAttributes android.view.SurfaceControl.getDisplayedContentSamplingAttributes(android.os.IBinder)
    Method Name =>public android.os.IBinder android.view.SurfaceControl.getHandle()
    Method Name =>public static android.view.Display$HdrCapabilities android.view.SurfaceControl.getHdrCapabilities(android.os.IBinder)
    Method Name =>public int android.view.SurfaceControl.getHeight()
    Method Name =>public static android.os.IBinder android.view.SurfaceControl.getInternalDisplayToken()
    Method Name =>public static long[] android.view.SurfaceControl.getPhysicalDisplayIds()
    Method Name =>public static android.os.IBinder android.view.SurfaceControl.getPhysicalDisplayToken(long)
    Method Name =>public static boolean android.view.SurfaceControl.getProtectedContentSupport()
    Method Name =>public int android.view.SurfaceControl.getWidth()
    Method Name =>public int java.lang.Object.hashCode()
    Method Name =>public void android.view.SurfaceControl.hide()
    Method Name =>public boolean android.view.SurfaceControl.isValid()
    Method Name =>public static void android.view.SurfaceControl.mergeToGlobalTransaction(android.view.SurfaceControl$Transaction)
    Method Name =>public final native void java.lang.Object.notify()
    Method Name =>public final native void java.lang.Object.notifyAll()
    Method Name =>public static void android.view.SurfaceControl.openTransaction()
    Method Name =>public void android.view.SurfaceControl.readFromParcel(android.os.Parcel)
    Method Name =>public void android.view.SurfaceControl.release()
    Method Name =>public void android.view.SurfaceControl.remove()
    Method Name =>public void android.view.SurfaceControl.reparent(android.view.SurfaceControl)
    Method Name =>public void android.view.SurfaceControl.reparentChildren(android.os.IBinder)
    Method Name =>public static void android.view.SurfaceControl.screenshot(android.os.IBinder,android.view.Surface)
    Method Name =>public static android.graphics.Bitmap android.view.SurfaceControl.screenshot(android.graphics.Rect,int,int,int)
    Method Name =>public static android.graphics.Bitmap android.view.SurfaceControl.screenshot(android.graphics.Rect,int,int,boolean,int)
    Method Name =>public static void android.view.SurfaceControl.screenshot(android.os.IBinder,android.view.Surface,android.graphics.Rect,int,int,boolean,int)
    Method Name =>public static android.graphics.Bitmap android.view.SurfaceControl.screenshot(android.graphics.Rect,int,int,int,int,boolean,int,java.lang.String)
    Method Name =>public static android.graphics.Bitmap android.view.SurfaceControl.screenshot(android.graphics.Rect,int,int,int,int,boolean,int,boolean,java.lang.String[])
    Method Name =>public static android.graphics.Bitmap android.view.SurfaceControl.screenshot(android.os.IBinder,android.graphics.Rect,int,int,int,int,boolean,int,java.lang.String)
    Method Name =>public static android.graphics.Bitmap android.view.SurfaceControl.screenshot(android.os.IBinder,android.graphics.Rect,int,int,int,int,boolean,int,boolean,java.lang.String[])
    Method Name =>public static android.view.SurfaceControl$ScreenshotGraphicBuffer android.view.SurfaceControl.screenshotToBuffer(android.os.IBinder,android.graphics.Rect,int,int,boolean,int)
    Method Name =>public static android.view.SurfaceControl$ScreenshotGraphicBuffer android.view.SurfaceControl.screenshotToBuffer(android.os.IBinder,android.graphics.Rect,int,int,int,int,boolean,int,boolean,java.lang.String[])
    Method Name =>public static android.view.SurfaceControl$ScreenshotGraphicBuffer android.view.SurfaceControl.screenshotToBufferWithSecureLayersUnsafe(android.os.IBinder,android.graphics.Rect,int,int,boolean,int)
    Method Name =>public static boolean android.view.SurfaceControl.setActiveColorMode(android.os.IBinder,int)
    Method Name =>public static boolean android.view.SurfaceControl.setActiveConfig(android.os.IBinder,int)
    Method Name =>public static boolean android.view.SurfaceControl.setAllowedDisplayConfigs(android.os.IBinder,int[])
    Method Name =>public void android.view.SurfaceControl.setAlpha(float)
    Method Name =>public static void android.view.SurfaceControl.setAnimationTransaction()
    Method Name =>public void android.view.SurfaceControl.setBufferSize(int,int)
    Method Name =>public void android.view.SurfaceControl.setColor(float[])
    Method Name =>public void android.view.SurfaceControl.setColorSpaceAgnostic(boolean)
    Method Name =>public void android.view.SurfaceControl.setColorTransform(float[],float[])
    Method Name =>public void android.view.SurfaceControl.setCornerRadius(float)
    Method Name =>public static boolean android.view.SurfaceControl.setDisplayBrightness(android.os.IBinder,float)
    Method Name =>public static void android.view.SurfaceControl.setDisplayLayerStack(android.os.IBinder,int)
    Method Name =>public static void android.view.SurfaceControl.setDisplayPowerMode(android.os.IBinder,int)
    Method Name =>public static void android.view.SurfaceControl.setDisplayProjection(android.os.IBinder,int,android.graphics.Rect,android.graphics.Rect)
    Method Name =>public static void android.view.SurfaceControl.setDisplaySize(android.os.IBinder,int,int)
    Method Name =>public static void android.view.SurfaceControl.setDisplaySurface(android.os.IBinder,android.view.Surface)
    Method Name =>public static boolean android.view.SurfaceControl.setDisplayedContentSamplingEnabled(android.os.IBinder,boolean,int,int)
    Method Name =>public void android.view.SurfaceControl.setGeometryAppliesWithResize()
    Method Name =>public void android.view.SurfaceControl.setLayer(int)
    Method Name =>public void android.view.SurfaceControl.setLayerStack(int)
    Method Name =>public void android.view.SurfaceControl.setMatrix(android.graphics.Matrix,float[])
    Method Name =>public void android.view.SurfaceControl.setMatrix(float,float,float,float)
    Method Name =>public void android.view.SurfaceControl.setOpaque(boolean)
    Method Name =>public void android.view.SurfaceControl.setOverrideScalingMode(int)
    Method Name =>public void android.view.SurfaceControl.setPosition(float,float)
    Method Name =>public void android.view.SurfaceControl.setRelativeLayer(android.view.SurfaceControl,int)
    Method Name =>public void android.view.SurfaceControl.setSecure(boolean)
    Method Name =>public void android.view.SurfaceControl.setTransparentRegionHint(android.graphics.Region)
    Method Name =>public void android.view.SurfaceControl.setWindowCrop(android.graphics.Rect)
    Method Name =>public void android.view.SurfaceControl.setWindowCrop(int,int)
    Method Name =>public void android.view.SurfaceControl.show()
    Method Name =>public java.lang.String android.view.SurfaceControl.toString()
    Method Name =>public final void java.lang.Object.wait() throws java.lang.InterruptedException
    Method Name =>public final void java.lang.Object.wait(long) throws java.lang.InterruptedException
    Method Name =>public final native void java.lang.Object.wait(long,int) throws java.lang.InterruptedException
    Method Name =>public void android.view.SurfaceControl.writeToParcel(android.os.Parcel,int)
    Method Name =>public void android.view.SurfaceControl.writeToProto(android.util.proto.ProtoOutputStream,long)
    create bitmap
    截图耗时:1
    shot success
    
    展开全文
  • Android截图命令screencap

    万次阅读 热门讨论 2014-06-07 13:28:52
    注意: 如果文件名以.png结尾时,它将保存为png文件 如果文件名没有给出,则结果被会被输出到stdout 截图保存到SD卡里再导出 $ adb shell screencap -p /sdcard/screen.png $ adb pull /sdcard/screen.png $ adb ...

    查看帮助命令

    bixiaopeng@bixiaopeng ~$ adb shell screencap -v
    screencap: invalid option -- v
    usage: screencap [-hp] [-d display-id] [FILENAME]
       -h: this message
       -p: save the file as a png.
       -d: specify the display id to capture, default 0.
    If FILENAME ends with .png it will be saved as a png.
    If FILENAME is not given, the results will be printed to stdout.
    
    

    注意:

    如果文件名以.png结尾时,它将保存为png文件

    如果文件名没有给出,则结果被会被输出到stdout

    截图保存到SD卡里再导出

    $ adb shell screencap -p /sdcard/screen.png
    $ adb pull /sdcard/screen.png
    $ adb shell rm /sdcard/screen.png
    

    这种方法比较麻烦,需要3步:1. 截图保存到sdcard 2.将图片导出 3.删除sdcard中的图片

    截图直接保存到电脑

    $ adb shell screencap -p | sed 's/\r$//' > screen.png
    

    执行adb shell 将\n转换\r\n, 因此需要用sed删除多余的\r

    如果直接当命令用还可以用 alias 包裝装起來:

    $ alias and-screencap="adb shell screencap -p | sed 's/\r$//'"
    $ and-screencap > screen.png 
    

    以后就可以方便的用and-screencap > 直接将截图保存到电脑上了


    订阅

    微信搜索“毕小烦”或者扫描下面的二维码,即可订阅我的文章。

    image.png

    如果文章对你有帮助,请随手点个赞吧!

    (完)

     
    展开全文
  • android 屏幕截图

    2017-12-05 10:54:50
    android 屏幕截图,基于android5.0后提供的接口截图,快捷方便
  • Android底层截图

    热门讨论 2013-07-30 09:51:41
    Android底层截图
  • Android屏幕截图方式总结

    千次阅读 2016-12-20 14:43:35
    借助PC端工具截图Android手机端截图 1、借助PC端工具截图 PC端截图可用的工具非常之多,从Android SDK提供的adb、ddms工具,到各大第三方助手应用宝、刷机精灵、豌豆荚等等。 工具虽多,但这些...

    0、Android屏幕截图方式:

    1. 借助PC端工具截图
    2. Android手机端截图

    1、借助PC端工具截图

    PC端截图可用的工具非常之多,从Android SDK提供的adb、ddms工具,到各大第三方助手应用宝、刷机精灵、豌豆荚等等。

    工具虽多,但这些它们的实现方式基本都是一样的,通过执行 adb shell screencap -p xxx.png 或 adb shell screenshot xxx.png 来获取屏幕截图。

    * screencap和screenshot有什么区别呢?

    screencap是从Android 2.3开始提供的一个系统级的截图工具,通过源码可以了解到screencap的实现方式,默认会从底层UI Surface去获取屏幕截图,如果失败则从linux kernel层的display framebuffer(`/dev/graphics/fb0`)去获取屏幕截图。
    
    screenshot是从Android 4.0开始提供的另一个截图的工具, 通过源码可以发现screenshot则是直接读取`/dev/graphics/fb0`去获取屏幕的图像数据。
    

    * 什么是/dev/graphics/fb0

    简单来说是linux kernel 2.x开始提供的,一个屏幕数据缓存的设备,理论上凡是使用linux内核的系统都会有这样一个东东,然后就可以通过读取里面的数据来获取当前屏幕显示的内容。需要详细了解可以自行谷歌一下。
    

    小结一下:

    PC端如何截图?

    1.下载应用宝PC版等工具 
    2.安装Android SDK,使用以下命令:

    • 系统是Android 2.3以上:
    1. adb shell screencap -p xxx.png
    • 系统是Android 4.0以上:
    1. adb shell screenshot xxx.png
    • 系统是Android 2.3以下,肿么办?

      1.将screenshot工具从Android源码中抠出来,编译为独立的工具。然后再通过screenshot进行截图。 
      2.使用我们沈大雄vincentshen同学开发的gsnapcap截图工具,已适配各大厂商各种奇葩机型,解决什么红屏花屏不在话下,还支持图像压缩噢。


    2、Android手机端截图

    Android手机端截图分两种情况,有root权限和无root权限。

    2.1 有root权限

    在系统已经root的情况下,可以通过在APP代码中执行`screencap -p xxx.png` 和 `screenshot xxx.png`来进行屏幕截图。原理和上述PC端截图是一样的,只不过在PC端截图,手机无需root权限。如果在APP中执行截图命令,则需要root权限。
    
    *任何在adb中可执行的命令,如果想在APP代码中执行,基本上都需要有root权限。例如bugreport、logcat(>=4.1)、screenrecord(>=4.4)等。
    

    代码示例:

    通过screncap命令截图

    1. Process process = null;
    2. try{
    3. process = Runtime.getRuntime().exec("su");
    4. PrintStream outputStream = null;
    5. try {
    6. outputStream = new PrintStream(new BufferedOutputStream(process.getOutputStream(), 8192));
    7. outputStream.println("screencap -p " + filePath);
    8. outputStream.flush();
    9. }catch(Exception e){
    10. Log.e(TAG, e);
    11. } finally {
    12. if (outputStream != null) {
    13. outputStream.close();
    14. }
    15. }
    16. process.waitFor();
    17. }catch(Exception e){
    18. Log.e(TAG, e);
    19. }finally {
    20. if(process != null){
    21. process.destroy();
    22. }
    23. }

    通过screnshot命令截图和上面是类似的,另外还可以通过调用Bugly自研的gsnapcap工具来进行截图。

    1. chmod 777 /dev/graphics/fb0
    2. gsnapcap xxx.png /dev/graphics/fb0 1

    最后一个参数为图像分辨率,1为屏幕原始分辨率。

    2.2 无root权限

    无root权限又分两种:

    • 系统自带截图
    • APP内截图

    2.2.1 系统自带截图

    系统自带截图有两种情况:

    • 同时按住 电源键 和 音量下键 两秒钟
    • 同时按住 电源键 和 Home键 两秒钟

    机型不同,系统自带的截图方式也不同,但基本上都是以上两种。

    2.2.2 APP内截图

    APP内截图又分两种:(-_-!我真的不是黑安卓,太多情况了。)

    • SurfaceView
    • GLSurfaceView

    SurfaceView和GLSurfaceView有什么不同,简单来说普通应用使用SurfaceView截图即可。游戏一般都是通过OpenGL实现的,那么则需要使用GLSurfaceView的方式进行截图。

    2.2.2.1 SurfaceView

    直接上代码:

    1. public String takeScreenShot(Activity activity){
    2. String filePath = FileUtils.getInstance().getStorePicFile(activity);
    3. View rootView = activity.getWindow().getDecorView();
    4. rootView.setDrawingCacheEnabled(true);
    5. rootView.buildDrawingCache();
    6. Bitmap bitmap = rootView.getDrawingCache();
    7. File imagePath = new File(filePath);
    8. FileOutputStream fos = null;
    9. try {
    10. fos = new FileOutputStream(imagePath);
    11. bitmap.compress(Bitmap.CompressFormat.JPEG, 100, fos);
    12. fos.flush();
    13. } catch (Exception e) {
    14. }finally {
    15. try{
    16. fos.close();
    17. bitmap.recycle();
    18. bitmap = null;
    19. }catch(Exception e){
    20. }
    21. rootView.destroyDrawingCache();
    22. rootView.setDrawingCacheEnabled(false);
    23. }
    24. return filePath;
    25. }

    takeScreenShot的参数必须为Activity类或其子类,不能是Context,这段代码是通过获取Activity的根节点view,并将其DrawingCache保存为图片,从而实现对该界面的截图。这个方法只能对APP自身的界面有效,出了APP就没有办法了。


    展开全文
  • android 截图demo

    2013-11-04 14:44:22
    android截图demo 代码简单 实现android中对手机屏幕的截图功能,
  • android屏幕截图

    2013-04-26 17:35:08
    android屏幕截图, 截图后保存路径用mnt/sdcard
  • Android 屏幕截图

    2017-03-08 15:08:56
    Android中实现屏幕截图的方式,包含提醒客户权限获取后的全机型适配方案。
  • android 截图Justin Duino贾斯汀·杜伊诺(Justin Duino)Android 11 introduced a number of changes, but one that might catch you off guard is how screenshots work. The functionality is mostly the same as ...
  • android轻量级的截屏工具非常的好用 1.把脚本放入指定目录下面: C:\Users\****\AppData\Local\Android\Sdk\platform-tools 2.把用手机打开想要截图的页面双击运行此脚本,图片就截取到脚本所在的文件夹
  • Android 系统截图

    2017-04-15 11:36:04
    如何实现android手机同时按下电源键和音量-按键截图android截图功能的实现是在SystemUI.apk中做的, 源码位于SystemUI\src\com\android\systemui\screenshot包下, 截图功能的实现简单,...
  • android adb 截图

    2011-06-03 10:40:51
    android adb 截图 ,需要去的root权限
  • android截图软件

    2011-06-01 23:22:27
    android截图软件,测试中,具体性能还在测试。
  • Android7.0拍照截图

    2018-11-07 10:57:20
    Android7.0拍照、相册 然后截图
  • screenshot-tests-for-android, 在Android测试测试期间生成快速确定的屏幕截图 Android屏幕截图 screenshot-tests-for-android是一个库,它可以生成快速确定的屏幕截图,同时在Android上运行测试测试。我们模拟( ) ...
  • android 截图scrollview

    2016-09-29 16:29:43
    import android.graphics.Bitmap; import android.graphics.Canvas; import android.view.View; import android.widget.ListView; import android.widget.ScrollView;... * 截图返回bitmap */ public class SurfaceC
  • Android截图功能

    2014-03-11 16:54:49
    andriod截图,不是手机自带截图功能,是自己做了个截图功能
  • android截图sdkThere’s no built-in way to take screenshots if your device is using a 2.x version of Android, such as Gingerbread or Froyo. However, you can take screenshots by connecting your Android ...
  • Android的屏幕截图测试Android的屏幕截图测试是一个库,可以在Android上运行检测测试时生成快速的确定性屏幕截图。 我们模仿Android的measure(),layout()和draw()生成Android屏幕截图测试screenshot-tests-...
  • Android截图功能Demo

    2014-03-02 19:23:03
    Android截图功能的Demo,帮助大家快速学习Android中的截图功能。
  • Android截图与长图分享

    千次阅读 2017-11-10 12:05:39
    1.第一步如何实现长截图Android长截屏– ScrollView,ListView及RecyclerView截屏 这个链接地址写的很清楚了,建议进行实际操作。概述:其实长截图就是将布局存成图像,由于Android中的所有可视组件都是绘制在屏幕...
  • android控件截图

    2016-12-06 09:59:30
    Android开发中可能有对控件,布局进行截图并显示的功能 以下说一下实现的方式,也算是记个笔记,防止以后用的时候自己忘记 <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" android:...

空空如也

空空如也

1 2 3 4 5 ... 20
收藏数 12,725
精华内容 5,090
关键字:

截图android