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
But I found that the jpeg picture produced was upside-down.This is not what I want.
Is there a way of rotating the frame before I save the frame?
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.
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.
You have two options:
drawFrame()
function takes an invert
argument, and modifies the matrix obtained from the SurfaceTexture if it's set.System.arrayCopy()
might be better than copying individual bytes with Java code.)