本文整理汇总了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();
}
});
}
}