按fadden @建議重新格式化爲問題和答案格式。我們如何使ExtractMpegFramesTest中的saveFrame()方法更高效?
ExtractMpegFramesTest_egl14.java.txt,方法saveFrame(),有一個循環,用於將RGBA重新排序爲ARGB進行位圖png壓縮(請參見下面的引用),如何優化?
// glReadPixels gives us a ByteBuffer filled with what is essentially big-endian RGBA
// data (i.e. a byte of red, followed by a byte of green...). We need an int[] filled
// with little-endian ARGB data to feed to Bitmap.
//
...
// So... we set the ByteBuffer to little-endian, which should turn the bulk IntBuffer
// get() into a straight memcpy on most Android devices. Our ints will hold ABGR data.
// Swapping B and R gives us ARGB. We need about 30ms for the bulk get(), and another
// 270ms for the color swap.
...
for (int i = 0; i < pixelCount; i++) {
int c = colors[i];
colors[i] = (c & 0xff00ff00) | ((c & 0x00ff0000) >> 16) | ((c & 0x000000ff) << 16);
}
好主意!這個交換循環在Java中並不是特別快。 – fadden
FWIW,我認爲提供建議的「官方」方法是詢問「我們如何使ExtractMpegFramesTest中的saveFrame()方法更有效?」,然後回答自己的問題。這樣鼓勵其他人也提出自己的答案。請參閱http://stackoverflow.com/help/self-answer。 – fadden
重新格式化,謝謝fadden! – miguelao