本文整理匯總了Java中android.graphics.PixelFormat.getPixelFormatInfo方法的典型用法代碼示例。如果您正苦於以下問題:Java PixelFormat.getPixelFormatInfo方法的具體用法?Java PixelFormat.getPixelFormatInfo怎麽用?Java PixelFormat.getPixelFormatInfo使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類android.graphics.PixelFormat
的用法示例。
在下文中一共展示了PixelFormat.getPixelFormatInfo方法的3個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: setPreviewCallback
import android.graphics.PixelFormat; //導入方法依賴的package包/類
/** 設置回調 */
protected void setPreviewCallback() {
Size size = mParameters.getPreviewSize();
if (size != null) {
PixelFormat pf = new PixelFormat();
PixelFormat.getPixelFormatInfo(mParameters.getPreviewFormat(), pf);
int buffSize = size.width * size.height * pf.bitsPerPixel / 8;
try {
camera.addCallbackBuffer(new byte[buffSize]);
camera.addCallbackBuffer(new byte[buffSize]);
camera.addCallbackBuffer(new byte[buffSize]);
camera.setPreviewCallbackWithBuffer(this);
} catch (OutOfMemoryError e) {
Log.e("Yixia", "startPreview...setPreviewCallback...", e);
}
Log.e("Yixia", "startPreview...setPreviewCallbackWithBuffer...width:" + size.width + " height:" + size.height);
} else {
camera.setPreviewCallback(this);
}
}
示例2: tryStartCapture
import android.graphics.PixelFormat; //導入方法依賴的package包/類
@SuppressWarnings("deprecation")
private int tryStartCapture(int width, int height, int frameRate) {
if (camera == null) {
Log.e(TAG, "Camera not initialized %d" + id);
return -1;
}
Log.d(TAG, "tryStartCapture: " + width +
"x" + height +", frameRate: " + frameRate +
", isCaptureRunning: " + isCaptureRunning +
", isSurfaceReady: " + isSurfaceReady +
", isCaptureStarted: " + isCaptureStarted);
if (isCaptureRunning || !isCaptureStarted) {
return 0;
}
CaptureCapabilityAndroid currentCapability =
new CaptureCapabilityAndroid();
currentCapability.width = width;
currentCapability.height = height;
currentCapability.maxFPS = frameRate;
PixelFormat.getPixelFormatInfo(PIXEL_FORMAT, pixelFormat);
Camera.Parameters parameters = camera.getParameters();
parameters.setPreviewSize(currentCapability.width,
currentCapability.height);
parameters.setPreviewFormat(PIXEL_FORMAT);
parameters.setPreviewFrameRate(currentCapability.maxFPS);
camera.setParameters(parameters);
int bufSize = width * height * pixelFormat.bitsPerPixel / 8;
cameraUtils.setCallback(this, numCaptureBuffers, bufSize, camera);
camera.startPreview();
previewBufferLock.lock();
expectedFrameSize = bufSize;
isCaptureRunning = true;
previewBufferLock.unlock();
isCaptureRunning = true;
return 0;
}
示例3: acquireScreenshot
import android.graphics.PixelFormat; //導入方法依賴的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;
}