window_buffer.bits
的数据不是根据window_buffer.width
而是根据window_buffer.stride
来决定的,
而目标区域要绘制在window_buffer.width
x window_buffer.height
区域内,因此要设置ROI。
ANativeWindow_setBuffersGeometry(window, rgba.cols, rgba.rows, WINDOW_FORMAT_RGBA_8888);
ANativeWindow_Buffer window_buffer;
if (ANativeWindow_lock(window, &window_buffer, nullptr)) {
ANativeWindow_release(window);
window = nullptr;
return;
}
long millis = currentTimeMillis();
Mat winBuffer(window_buffer.height,window_buffer.stride,CV_8UC4,window_buffer.bits);
Mat roi(winBuffer,Rect(0,0, rgba.cols, rgba.rows));
rgba.copyTo(roi);
LOGD("Cost time %d ms",(currentTimeMillis()-millis));
网友评论