本文整理汇总了Java中android.view.Display.getPixelFormat方法的典型用法代码示例。如果您正苦于以下问题:Java Display.getPixelFormat方法的具体用法?Java Display.getPixelFormat怎么用?Java Display.getPixelFormat使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类android.view.Display
的用法示例。
在下文中一共展示了Display.getPixelFormat方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: detectBestPixelFormat
import android.view.Display; //导入方法依赖的package包/类
private int detectBestPixelFormat() {
//Skip check if this is a new device as it will be RGBA_8888 by default.
if (isRGBA_8888ByDefault) {
return PixelFormat.RGBA_8888;
}
Context context = getContext();
WindowManager wm = (WindowManager) context.getSystemService(Context.WINDOW_SERVICE);
Display display = wm.getDefaultDisplay();
//Get display pixel format
int displayFormat = display.getPixelFormat();
if ( PixelFormat.formatHasAlpha(displayFormat) ) {
return displayFormat;
} else {
return PixelFormat.RGB_565;//Fallback for those who don't support Alpha
}
}
示例2: acquireScreenshot
import android.view.Display; //导入方法依赖的package包/类
@SuppressWarnings("deprecation")
public static Bitmap acquireScreenshot(Context context) {
WindowManager mWinManager = (WindowManager) context
.getSystemService(Context.WINDOW_SERVICE);
DisplayMetrics metrics = new DisplayMetrics();
Display display = mWinManager.getDefaultDisplay();
display.getMetrics(metrics);
// 屏幕高
int height = metrics.heightPixels;
// 屏幕的宽
int width = metrics.widthPixels;
int pixelformat = display.getPixelFormat();
PixelFormat localPixelFormat1 = new PixelFormat();
PixelFormat.getPixelFormatInfo(pixelformat, localPixelFormat1);
// 位深
int deepth = localPixelFormat1.bytesPerPixel;
byte[] arrayOfByte = new byte[height * width * deepth];
try {
// 读取设备缓存,获取屏幕图像流
InputStream localInputStream = readAsRoot();
DataInputStream localDataInputStream = new DataInputStream(
localInputStream);
localDataInputStream.readFully(arrayOfByte);
localInputStream.close();
int[] tmpColor = new int[width * height];
int r, g, b;
for (int j = 0; j < width * height * deepth; j += deepth) {
b = arrayOfByte[j] & 0xff;
g = arrayOfByte[j + 1] & 0xff;
r = arrayOfByte[j + 2] & 0xff;
tmpColor[j / deepth] = (r << 16) | (g << 8) | b | (0xff000000);
}
// 构建bitmap
Bitmap scrBitmap = Bitmap.createBitmap(tmpColor, width, height,
Bitmap.Config.ARGB_8888);
return scrBitmap;
} catch (Exception e) {
L.d( "#### 读取屏幕截图失败");
e.printStackTrace();
}
return null;
}