本文整理匯總了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;
}