使用前置摄像头翻转图像以获得wp8

时间:2015-07-01 19:20:12

标签: windows-phone-8 lumia-imaging-sdk nokia-imaging-sdk

我正在为我的Windows手机应用程序使用lumia imaging sdk。我主要使用前置摄像头。我也使用VideoBrush来捕捉图像。当我试图用前置摄像头拍照时,它可以很好地工作,但是当拍摄图像时,图像会被翻转并保存(就像镜像效果一样)。

<Canvas x:Name="VideoCanvas" Width="480" Height="640" RenderTransformOrigin="0.5,0.5">
    <Canvas.RenderTransform>
        <CompositeTransform ScaleX="-1"/>
    </Canvas.RenderTransform>
    <Canvas.Background>
        <VideoBrush x:Name="videoBrush"/>
    </Canvas.Background>                
</Canvas>

上面的Scale="-1"有助于初始化相机,但捕获任务将其存储为镜像。下面是用于捕获图像的代码。这种镜面效果可以在这里操纵吗?

private async Task Capture()
{
        if (!_capturing)
        {
            _capturing = true;

            MemoryStream stream = new MemoryStream();

            CameraCaptureSequence sequence = _dataContext.Device.CreateCaptureSequence(1);
            sequence.Frames[0].CaptureStream = stream.AsOutputStream();

            await _dataContext.Device.PrepareCaptureSequenceAsync(sequence);
            await sequence.StartCaptureAsync();

            _dataContext.ImageStream = stream;

            _capturing = false;
        }
}

或者有没有办法翻转和保存捕获的图像(如 LumiaSelfie 应用程序)?请帮我解决一下这个。提前谢谢。

1 个答案:

答案 0 :(得分:0)

在您的Lumia Imaging SDK渲染链中,您可以添加一个Flipfilter:https://msdn.microsoft.com/en-us/library/lumia.imaging.transforms.flipfilter.aspx

示例:

    <link href='http://fonts.googleapis.com/css?family=Montserrat' rel='stylesheet' type='text/css'>

    <script type="text/javascript" src="https://ajax.googleapis.com/ajax/libs/jquery/1.7.2/jquery.min.js"></script>

    <link rel="stylesheet" type="text/css" media="all" href="fancybox/jquery.fancybox.css">
    <script type="text/javascript" src="fancybox/jquery.fancybox.js?v=2.0.6"></script>

    <script src="js/jquery.flow.1.2.auto.js" type="text/javascript"></script>  

    <link rel="stylesheet" type="text/css" href="//cdn.jsdelivr.net/jquery.slick/1.5.0/slick.css"/>
    <script type="text/javascript" src="//cdn.jsdelivr.net/jquery.slick/1.5.0/slick.min.js"></script>

<div class="carousel">
    <div><img src="img/carousel/1.jpg" /></div>
    <div><img src="img/carousel/2.jpg" /></div>
    <div><img src="img/carousel/coutout2.jpg" /></div>
    <div><img src="img/carousel/cutout.jpg" /></div>
    <div><img src="img/carousel/cutout1.jpg" /></div>
</div>


 <script type="text/javascript">

             $(document).ready(function() {

                $(".modalbox").fancybox();

                $('.carousel').slick({
                    slidesToShow: 1,
                    slidesToScroll: 1,
                    autoplay: true,
                    autoplaySpeed: 450,
                    adaptiveHeight: true
                    });

                $("#Logo").show();


    $("#contact").submit(function() { return false; });

                //send email
    $("#send").on("click", function(){
        var emailval  = $("#email").val();
        var msgval    = $("#message").val();
        var msglen    = msgval.length;
        var mailvalid = validateEmail(emailval);

                    //
        if(mailvalid == false) {
            $("#email").addClass("error");
        }
        else if(mailvalid == true){
            $("#email").removeClass("error");
        }

        if(msglen < 4) {
            $("#msg").addClass("error");
        }
        else if(msglen >= 4){
            $("#msg").removeClass("error");
        }
        //

                     mailvalid == true

    if(mailvalid == true     && msglen >= 4) {
            $("#send").replaceWith("<em>sending...</em>");

            $.ajax({
                                    type: 'POST',
                url: 'contact_form/contact.php',
                data: $("#contact").serialize(),
                success: function(data) {
                    if(data == "true") {
                        $("#contact").fadeOut("fast", function(){
                            $(this).before("<p><strong>Success! Your feedback has been sent, thanks :)</strong></p>");
                            setTimeout("$.fancybox.close()", 1000);
                        });
                    }
                }
            });
        }
    });


            //validate email
            function validateEmail(email) { 
    var reg = /^(([^<>()[\]\\.,;:\s@\"]+(\.[^<>()[\]\\.,;:\s@\"]+)*)|(\".+\"))@((\[[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\])|(([a-zA-Z\-0-9]+\.)+[a-zA-Z]{2,}))$/;
    return reg.test(email);
}
        });