本文整理匯總了Java中android.graphics.ImageFormat.JPEG屬性的典型用法代碼示例。如果您正苦於以下問題:Java ImageFormat.JPEG屬性的具體用法?Java ImageFormat.JPEG怎麽用?Java ImageFormat.JPEG使用的例子?那麽, 這裏精選的屬性代碼示例或許可以為您提供幫助。您也可以進一步了解該屬性所在類android.graphics.ImageFormat
的用法示例。
在下文中一共展示了ImageFormat.JPEG屬性的3個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: imageToByteArray
public static byte[] imageToByteArray(Image image) {
byte[] data = null;
if (image.getFormat() == ImageFormat.JPEG) {
Image.Plane[] planes = image.getPlanes();
ByteBuffer buffer = planes[0].getBuffer();
data = new byte[buffer.capacity()];
buffer.get(data);
return data;
} else if (image.getFormat() == ImageFormat.YUV_420_888) {
data = NV21toJPEG(
YUV_420_888toNV21(image),
image.getWidth(), image.getHeight());
}
return data;
}
示例2: initCamera
private void initCamera(boolean front) {
CameraInfo info = null;
ArrayList<CameraInfo> cameraInfos = CameraController.getInstance().getCameras();
if (cameraInfos == null) {
return;
}
for (int a = 0; a < cameraInfos.size(); a++) {
CameraInfo cameraInfo = cameraInfos.get(a);
if (isFrontface && cameraInfo.frontCamera != 0 || !isFrontface && cameraInfo.frontCamera == 0) {
info = cameraInfo;
break;
}
}
if (info == null) {
return;
}
float size4to3 = 4.0f / 3.0f;
float size16to9 = 16.0f / 9.0f;
float screenSize = (float) Math.max(AndroidUtilities.displaySize.x, AndroidUtilities.displaySize.y) / Math.min(AndroidUtilities.displaySize.x, AndroidUtilities.displaySize.y);
Size aspectRatio;
int wantedWidth;
int wantedHeight;
if (Math.abs(screenSize - size4to3) < 0.1f) {
aspectRatio = new Size(4, 3);
wantedWidth = 1280;
wantedHeight = 960;
} else {
aspectRatio = new Size(16, 9);
wantedWidth = 1280;
wantedHeight = 720;
}
if (textureView.getWidth() > 0 && textureView.getHeight() > 0) {
int width = Math.min(AndroidUtilities.displaySize.x, AndroidUtilities.displaySize.y);
int height = width * aspectRatio.getHeight() / aspectRatio.getWidth();
previewSize = CameraController.chooseOptimalSize(info.getPreviewSizes(), width, height, aspectRatio);
}
Size pictureSize = CameraController.chooseOptimalSize(info.getPictureSizes(), wantedWidth, wantedHeight, aspectRatio);
if (pictureSize.getWidth() >= 1280 && pictureSize.getHeight() >= 1280) {
if (Math.abs(screenSize - size4to3) < 0.1f) {
aspectRatio = new Size(3, 4);
} else {
aspectRatio = new Size(9, 16);
}
Size pictureSize2 = CameraController.chooseOptimalSize(info.getPictureSizes(), wantedHeight, wantedWidth, aspectRatio);
if (pictureSize2.getWidth() < 1280 || pictureSize2.getHeight() < 1280) {
pictureSize = pictureSize2;
}
}
SurfaceTexture surfaceTexture = textureView.getSurfaceTexture();
if (previewSize != null && surfaceTexture != null) {
surfaceTexture.setDefaultBufferSize(previewSize.getWidth(), previewSize.getHeight());
cameraSession = new CameraSession(info, previewSize, pictureSize, ImageFormat.JPEG);
CameraController.getInstance().open(cameraSession, surfaceTexture, new Runnable() {
@Override
public void run() {
if (cameraSession != null) {
cameraSession.setInitied();
}
checkPreviewMatrix();
}
}, new Runnable() {
@Override
public void run() {
if (delegate != null) {
delegate.onCameraCreated(cameraSession.cameraInfo.camera);
}
}
});
}
}
示例3: initCamera
private void initCamera(boolean front) {
CameraInfo info = null;
ArrayList<CameraInfo> cameraInfos = CameraController.getInstance().getCameras();
for (int a = 0; a < cameraInfos.size(); a++) {
CameraInfo cameraInfo = cameraInfos.get(a);
if (isFrontface && cameraInfo.frontCamera != 0 || !isFrontface && cameraInfo.frontCamera == 0) {
info = cameraInfo;
break;
}
}
if (info == null) {
return;
}
float size4to3 = 4.0f / 3.0f;
float size16to9 = 16.0f / 9.0f;
float screenSize = (float) Math.max(AndroidUtilities.displaySize.x, AndroidUtilities.displaySize.y) / Math.min(AndroidUtilities.displaySize.x, AndroidUtilities.displaySize.y);
Size pictureSize;
if (Math.abs(screenSize - size4to3) < 0.1f) {
pictureSize = new Size(4, 3);
} else {
pictureSize = new Size(16, 9);
}
if (textureView.getWidth() > 0 && textureView.getHeight() > 0) {
int width = Math.min(AndroidUtilities.displaySize.x, AndroidUtilities.displaySize.y);
int height = width * pictureSize.getHeight() / pictureSize.getWidth();
previewSize = CameraController.chooseOptimalSize(info.getPreviewSizes(), width, height, pictureSize);
}
pictureSize = CameraController.chooseOptimalSize(info.getPictureSizes(), 1280, 1280, pictureSize);
if (previewSize != null && textureView.getSurfaceTexture() != null) {
textureView.getSurfaceTexture().setDefaultBufferSize(previewSize.getWidth(), previewSize.getHeight());
cameraSession = new CameraSession(info, previewSize, pictureSize, ImageFormat.JPEG);
CameraController.getInstance().open(cameraSession, textureView.getSurfaceTexture(), new Runnable() {
@Override
public void run() {
if (cameraSession != null) {
cameraSession.setInitied();
}
checkPreviewMatrix();
}
});
}
}