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


Java RendererCommon.getLayoutMatrix方法代码示例

本文整理汇总了Java中org.webrtc.RendererCommon.getLayoutMatrix方法的典型用法代码示例。如果您正苦于以下问题:Java RendererCommon.getLayoutMatrix方法的具体用法?Java RendererCommon.getLayoutMatrix怎么用?Java RendererCommon.getLayoutMatrix使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在org.webrtc.RendererCommon的用法示例。


在下文中一共展示了RendererCommon.getLayoutMatrix方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: captureBitmapFromTexture

import org.webrtc.RendererCommon; //导入方法依赖的package包/类
private Bitmap captureBitmapFromTexture(I420Frame i420Frame) {
    int width = i420Frame.rotatedWidth();
    int height = i420Frame.rotatedHeight();
    int outputFrameSize = width * height * 3 / 2;
    ByteBuffer outputFrameBuffer = ByteBuffer.allocateDirect(outputFrameSize);
    final float frameAspectRatio = (float) i420Frame.rotatedWidth() /
            (float) i420Frame.rotatedHeight();
    final float[] rotatedSamplingMatrix =
            RendererCommon.rotateTextureMatrix(i420Frame.samplingMatrix,
                    i420Frame.rotationDegree);
    final float[] layoutMatrix = RendererCommon.getLayoutMatrix(false,
            frameAspectRatio,
            (float) width / height);
    final float[] texMatrix = RendererCommon.multiplyMatrices(rotatedSamplingMatrix,
            layoutMatrix);
    /*
     * YuvConverter must be instantiated on a thread that has an active EGL context. We know
     * that renderFrame is called from the correct render thread therefore
     * we defer instantiation of the converter until frame arrives.
     */
    YuvConverter yuvConverter = new YuvConverter();
    yuvConverter.convert(outputFrameBuffer,
            width,
            height,
            width,
            i420Frame.textureId,
            texMatrix);

    // Now we need to unpack the YUV data into planes
    byte[] data = outputFrameBuffer.array();
    int offset = outputFrameBuffer.arrayOffset();
    int stride = width;
    ByteBuffer[] yuvPlanes = new ByteBuffer[] {
            ByteBuffer.allocateDirect(width * height),
            ByteBuffer.allocateDirect(width * height / 4),
            ByteBuffer.allocateDirect(width * height / 4)
    };
    int[] yuvStrides = new int[] {
            width,
            (width + 1) / 2,
            (width + 1) / 2
    };

    // Write Y
    yuvPlanes[0].put(data, offset, width * height);

    // Write U
    for (int r = height ; r < height * 3 / 2; ++r) {
        yuvPlanes[1].put(data, offset + r * stride, stride / 2);
    }

    // Write V
    for (int r = height ; r < height * 3 / 2 ; ++r) {
        yuvPlanes[2].put(data, offset + r * stride + stride / 2, stride / 2);
    }

    // Convert the YuvImage
    YuvImage yuvImage = i420ToYuvImage(yuvPlanes, yuvStrides, width, height);

    ByteArrayOutputStream stream = new ByteArrayOutputStream();
    Rect rect = new Rect(0, 0, yuvImage.getWidth(), yuvImage.getHeight());

    // Compress YuvImage to jpeg
    yuvImage.compressToJpeg(rect, 100, stream);

    // Convert jpeg to Bitmap
    byte[] imageBytes = stream.toByteArray();

    // Release YUV Converter
    yuvConverter.release();

    return BitmapFactory.decodeByteArray(imageBytes, 0, imageBytes.length);
}
 
开发者ID:twilio,项目名称:video-quickstart-android,代码行数:74,代码来源:SnapshotVideoRenderer.java


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