是否有更好的解决方案来获取视频帧?
缩放图像部分是否有问题?
如果我不使用位图(删除代码)并运行相同的场景(打开视图10次),探查器显示的内存使用情况将比使用正在获取的位图时小30-40MB来自import java.io.File;
function checkPages(pagesCount) {
function checkPage(i) {
if (i <= pagesCount) {
getData("url-to-get-data", i).done(function(result) {
var today = checkToday(result);
if (today == null) { // only get next page if today is null
checkPage(i+1);
}
});
}
}
checkPage(2);
}
请注意
mediaMetadataRetriever
和private fun getScaledBitmap(timeUs: Long): Bitmap? { try { mediaMetadataRetriever?.getFrameAtTime(timeUs, MediaMetadataRetriever.OPTION_CLOSEST_SYNC)?.let { val result = Bitmap.createBitmap(frameWidth, frameHeight, it.config) val canvas = Canvas(result) val scaleX = frameWidth.toFloat() / it.width.toFloat() val scaleY = frameHeight.toFloat() / it.height.toFloat() val scale = if (scaleX > scaleY) scaleX else scaleY val w = (it.width * scale).toInt() val h = (it.height * scale).toInt() val srcRect = Rect(0, 0, it.width, it.height) val destRect = Rect((frameWidth - w) / 2, (frameHeight - h) / 2, w, h) canvas.drawBitmap(it, srcRect, destRect, null) it.recycle() return result } } catch (e: Exception) { e.printStackTrace() } return null }
是框架的所需大小