当前位置: 首页>>代码示例>>Java>>正文


Java ImageFormat.JPEG属性代码示例

本文整理汇总了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;
}
 
开发者ID:InnoFang,项目名称:FamilyBond,代码行数:15,代码来源:ImageUtil.java

示例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);
                }
            }
        });
    }
}
 
开发者ID:chengzichen,项目名称:KrGallery,代码行数:70,代码来源:CameraView.java

示例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();
            }
        });
    }
}
 
开发者ID:pooyafaroka,项目名称:PlusGram,代码行数:42,代码来源:CameraView.java


注:本文中的android.graphics.ImageFormat.JPEG属性示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。