通过Grafika的saveFrame产生的画面是上下颠倒 [英] Picture produced by saveFrame of Grafika is upside-down

查看:1047
本文介绍了通过Grafika的saveFrame产生的画面是上下颠倒的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我写了根据连续捕获activity.I想保存视频为JPEG文件的第一帧演示,所以我用这已经是美元的Grafika ppared p $的saveFrame()函数。该函数的源$ C ​​$ c是如下:
<一href=\"https://github.com/google/grafika/blob/master/src/com/android/grafika/gles/EglSurfaceBase.java\" rel=\"nofollow\">https://github.com/google/grafika/blob/master/src/com/android/grafika/gles/EglSurfaceBase.java

I wrote a demo according to Continuous capture activity.I wanted to save the first frame of the video as a jpeg file, so I used the saveFrame() function which was already prepared by Grafika. The source code of the function is as follows: https://github.com/google/grafika/blob/master/src/com/android/grafika/gles/EglSurfaceBase.java

但是我发现,公司生产的JPEG图片是颠倒down.This是不是我想要的。

But I found that the jpeg picture produced was upside-down.This is not what I want.

有没有我之前保存框架旋转框架的方法吗?

旋转位图不是一个优雅的解决方案,因为我们可能会遇到一些其他情况,如视频聊天。的视频的每个帧被发送到远端对等体,则该远程人员将会看到一个倒置式视频。所以,之前,它是连接codeD要旋转每一帧。

Rotating the bitmap is not a graceful solution,because we might encounter some other situations such as video chatting. Each frame of the video is sent to the remote peer, then the remote person will see a upside-up video. So we should rotate every frame before it is encoded.

推荐答案

您不想要的旋转的框,你要的翻转的框架。

You don't want to rotate the frame, you want to flip the frame.

这种情况的存在,因为位图认为,(0,0)是在左上角,但GLES认为,(0,0)是在左下角。 glReadPixels()开始填充从顶部,这位图认为是底部的缓冲,所以你最终用一个倒的形象。

The situation exists because Bitmap thinks (0,0) is in the top-left corner, but GLES thinks (0,0) is in the bottom-left corner. glReadPixels() starts filling the buffer from the top, which Bitmap thinks is the bottom, so you end up with an upside-down image.

您有两种选择:


  1. 绘制与GLES帧倒置,然后抓住它,你现在的样子。这就是 ExtractMpegFramesTest code不 - 注意并条机()如果它被设置函数接受一个颠倒参数,并修改从获得表面纹理矩阵。

  2. 绘制并提取帧作为你现在,然后将它们转换为位图之前翻转在缓冲器中的像素。这是左右移动的字节一件简单的事。它会增加一些开销,但你已经有点慢,因为JPEG COM pression的。 (复制整行以 System.arrayCopy()可能会比复制与Java code单个字节更好。)

  1. Draw the frame upside-down with GLES, then grab it as you are now. This is what the ExtractMpegFramesTest code does -- note the drawFrame() function takes an invert argument, and modifies the matrix obtained from the SurfaceTexture if it's set.
  2. Draw and extract the frame as you are now, then flip the pixels in the buffer before converting them to a Bitmap. This is a simple matter of moving bytes around. It will add some overhead, but you're already kind of slow because of the JPEG compression. (Copying whole lines with System.arrayCopy() might be better than copying individual bytes with Java code.)

这篇关于通过Grafika的saveFrame产生的画面是上下颠倒的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆