最好能提供一个简单的示例. . 谢谢先
------解决方案--------------------
int lock_surface(unsigned char **ppbuf, int *width, int *height, int *bpp){
unsigned short *surfaceBuffer;
Surface::SurfaceInfo info;
Region dirtyRegion;
// invalid the whole surface
dirtyRegion.set(Rect(0x3FFF, 0x3FFF));
if(g_surface == NULL){
LOGD("Error! surface not initialized!\n");
return -1;
}
status_t err = g_surface->lock(&info, &dirtyRegion);
if (err < 0) {
return -1;
}
*ppbuf = (unsigned char *)info.bits;
*width = info.w;
*height = info.h;
switch(info.format){
case PIXEL_FORMAT_RGBA_8888:
case PIXEL_FORMAT_RGBX_8888:
case PIXEL_FORMAT_BGRA_8888:
*bpp = 4;
break;
case PIXEL_FORMAT_RGB_888:
*bpp = 3;
break;
case PIXEL_FORMAT_RGB_565:
case PIXEL_FORMAT_RGBA_5551:
case PIXEL_FORMAT_RGBA_4444:
*bpp = 2;
break;
default:
return -1;
}
return 0;
}
int unlock_and_post_surface(void){
if(g_surface == NULL){
LOGD("Error! surface not initialized!\n");
return -1;
}
return g_surface->unlockAndPost();
}
调用的地方:
if(lock_surface(&graphic_buf, &output_width, &output_height, &bpp) < 0){
LOGE("ERROR! can not lock canvas");
continue;
}
yuv420_2_rgb565(yuv_location, graphic_buf,
output_width, output_height, output_width<<1);
unlock_and_post_surface();
怎么获取surfaceView的native surface,从android_view_surface.cpp中剥出来就可以了。