当前位置: 动力学知识库 > 问答 > 编程问答 >

opencv - How to write to file (encode) modified camera frames in Windows Phone 8

问题描述:

I have custom an camera app in Windows Phone 8. I need add a watermark image to each frame from camera capture and then record to a video.

I can customise each frame from the preview using the following code:

int[] pixelData = new int[(int)(camera.PreviewResolution.Width * camera.PreviewResolution.Height)];

camera.GetPreviewBufferArgb32(pixelData);

return pixelData;

and write it back to the preview.

my problem is that while I can show the frames on the screen while the user is recording a movie using the camera I cant find a working solution for WP8 to encode the frames and audio to save to a file.

I already tried opencv,libav and others without success,

if anyone can point me to the right direction it would be greatly appreciated.

网友答案:

You can do it like this.

private void GetCameraPicture_Click(object sender, RoutedEventArgs e)
{
    Microsoft.Phone.Tasks.CameraCaptureTask cameraCaptureTask = new Microsoft.Phone.Tasks.CameraCaptureTask();
    cameraCaptureTask.Completed += cct_Completed;
    cameraCaptureTask.Show();
}

try
{
    if (e.TaskResult == Microsoft.Phone.Tasks.TaskResult.OK)
    {
        var imageStream = e.ChosenPhoto;
        var name = e.OriginalFileName;
        using (MemoryStream mem = new MemoryStream())
        {
            TextBlock tb = new TextBlock() { Text = DateTime.Now.ToString("dd MMM yyyy, HH:mm"), Foreground = new SolidColorBrush(Color.FromArgb(128, 0, 0, 0)), FontSize = 40 };
            BitmapImage finalImage = new BitmapImage();
            finalImage.SetSource(imageStream);
            WriteableBitmap wbFinal = new WriteableBitmap(finalImage);
            wbFinal.Render(tb, null);
            wbFinal.Invalidate();
            wbFinal.SaveJpeg(mem, wbFinal.PixelWidth, wbFinal.PixelHeight, 0, 100);
            mem.Seek(0, System.IO.SeekOrigin.Begin);
            MediaLibrary lib = new MediaLibrary();
            lib.SavePictureToCameraRoll("Copy" + name, mem.ToArray());
        }
    }
}
catch (Exception exp) { MessageBox.Show(exp.Message); }

Hope it may help you.

分享给朋友:
您可能感兴趣的文章:
随机阅读: