OK6410预览并实现截图操作(RGB565)(2)

if((n =(ioctl(v4l2_fd, VIDIOC_QUERYCAP, &caminfo)))<0)
   printf("Error: failed to get camera info.%d\n",n);
  //设置图象模式
  fmt.type = V4L2_BUF_TYPE_VIDEO_CAPTURE;

fmt.fmt.pix.width = 480;
 fmt.fmt.pix.height = 272;

fmt.fmt.pix.pixelformat = V4L2_PIX_FMT_RGB565;
 fmt.fmt.pix.priv = V4L2_FMT_OUT; 
 if((ioctl(v4l2_fd, VIDIOC_S_FMT, &fmt))<0)
  printf("Error: failed to set video format.\n");

int type = V4L2_BUF_TYPE_VIDEO_CAPTURE;
 if((ioctl(v4l2_fd, VIDIOC_STREAMON, &type))<0)
  printf("start to get pic %d\n",(int)fmt.fmt.pix.sizeimage);

int ii = 0;
 while(1){
  n=read(v4l2_fd, fb_buf, 480*272*2);
  if (ii == 0 && n > 0) {
   int data_fd=-1;
   
   printf("read Data Length:%d\n", n);
   preview_buf =  malloc(n);
   memcpy(preview_buf, fb_buf, n);
   
   
   char bmpfilename[30];
   sprintf(bmpfilename, "/sdcard/photo%d.bmp",1);
   
   if((data_fd = open(bmpfilename,O_CREAT|O_RDWR,0777))<0){
    printf("Error: failed to creat photo.bmp.\n");
    return 0;
   }
   printf("bmpfilename is %s\n",bmpfilename);

writebmp(data_fd);
   if(data_fd>0)
                  close(data_fd);
   free(preview_buf);
    ii = 1;
   }
 }

}

内容版权声明:除非注明,否则皆为本站原创文章。

转载注明出处:http://www.heiqu.com/3d833aeb8069842351d4d8b50e273a7e.html