大佬教程收集整理的这篇文章主要介绍了java – 如何拍摄屏幕快照不仅在Android中的应用程序与代码,大佬教程大佬觉得挺不错的,现在分享给大家,也给大家做个参考。
View view = getWindow().getDecorView().getRootView(); view.setDrawingCacheEnabled(true); Bitmap bitmap = Bitmap.createBitmap(view.getDrawingCache()); view.setDrawingCacheEnabled(false); saveImageToAppFolder(bitmap);
Process sh = Runtime.getRuntime().exec("su",null,null); OutputStream os = sh.getOutputStream(); os.write(("/system/bin/screencap -p " + Environment.getExternalStorageDirectory()+ "/img.png").getBytes("ASCII")); os.flush(); os.close(); sh.waitFor()
并将该文件加载到位图中,使用
public static Bitmap decodeSampledBitmapFromFile(String path,int reqWidth,int reqHeight) { // First decode with inJustDecodeBounds=true to check dimensions final BitmapFactory.options options = new BitmapFactory.options(); options.inJustDecodeBounds = true; BitmapFactory.decodeFile(path,options); // Calculate inSampleSize options.inSampleSize = calculateInSampleSize(options,reqWidth,reqHeight); // Decode bitmap with inSampleSize set options.inJustDecodeBounds = false; return BitmapFactory.decodeFile(path,options); } public static int calculateInSampleSize( BitmapFactory.options options,int reqHeight) { // Raw height and width of image final int height = options.outHeight; final int width = options.outWidth; int inSampleSize = 1; if (height > reqHeight || width > reqWidth) { final int halfHeight = height / 2; final int halfWidth = width / 2; // Calculate the largest inSampleSize value that is a power of 2 and keeps both // height and width larger than the requested height and width. while ((halfHeight / inSampleSizE) > reqHeight && (halfWidth / inSampleSizE) > reqWidth) { inSampleSize *= 2; } } return inSampleSize; }
以上是大佬教程为你收集整理的java – 如何拍摄屏幕快照不仅在Android中的应用程序与代码全部内容,希望文章能够帮你解决java – 如何拍摄屏幕快照不仅在Android中的应用程序与代码所遇到的程序开发问题。
如果觉得大佬教程网站内容还不错,欢迎将大佬教程推荐给程序员好友。
本图文内容来源于网友网络收集整理提供,作为学习参考使用,版权属于原作者。
如您有任何意见或建议可联系处理。小编QQ:384754419,请注明来意。