Exemplo n.º 1
0
        private void OnPinchUpdated(object sender, PinchGestureUpdatedEventArgs e)
        {
            switch (e.Status)
            {
            case GestureStatus.Started:
                StartScale = CapturedImage.Scale;
                AnchorX    = e.ScaleOrigin.X;
                AnchorY    = e.ScaleOrigin.Y;
                break;

            case GestureStatus.Running:
                double current = CapturedImage.Scale + (e.Scale - 1) * StartScale;
                CapturedImage.Scale = Clamp(current, MIN_SCALE * (1 - OVERSHOOT), MAX_SCALE * (1 + OVERSHOOT));
                break;

            case GestureStatus.Completed:
                if (Scale > MAX_SCALE)
                {
                    CapturedImage.ScaleTo(MAX_SCALE, 250, Easing.SpringOut);
                }
                else if (Scale < MIN_SCALE)
                {
                    CapturedImage.ScaleTo(MIN_SCALE, 250, Easing.SpringOut);
                }

                break;
            }
        }
        void ReleaseDesignerOutlets()
        {
            if (Back != null)
            {
                Back.Dispose();
                Back = null;
            }

            if (CapturedImage != null)
            {
                CapturedImage.Dispose();
                CapturedImage = null;
            }

            if (CaptureImage != null)
            {
                CaptureImage.Dispose();
                CaptureImage = null;
            }

            if (ClearPicture != null)
            {
                ClearPicture.Dispose();
                ClearPicture = null;
            }

            if (Describe != null)
            {
                Describe.Dispose();
                Describe = null;
            }

            if (Emotion != null)
            {
                Emotion.Dispose();
                Emotion = null;
            }

            if (Front != null)
            {
                Front.Dispose();
                Front = null;
            }

            if (ImageData != null)
            {
                ImageData.Dispose();
                ImageData = null;
            }

            if (OCR != null)
            {
                OCR.Dispose();
                OCR = null;
            }
        }
Exemplo n.º 3
0
        void ta_Completed(object sender, EventArgs e)
        {
            Dispatcher.Invoke(delegate()
            {
                ThicknessAnimation ta = new ThicknessAnimation();
                ta.From       = new Thickness(0);
                ta.To         = new Thickness(0, 0, 0, 0);
                ta.Duration   = new Duration(TimeSpan.FromSeconds(0));
                ta.Completed += ta_FixCompleted;

                CapturedImage.BeginAnimation(MarginProperty, ta);
            });
        }
Exemplo n.º 4
0
 private void OnTapped(object sender, EventArgs e)
 {
     if (CapturedImage.Scale > MIN_SCALE || CapturedImage.Scale < MIN_SCALE)
     {
         CapturedImage.ScaleTo(MIN_SCALE, 250, Easing.CubicInOut);
         CapturedImage.TranslateTo(0, 0, 250, Easing.CubicInOut);
     }
     else
     {
         AnchorX = AnchorY = 0.5; //TODO tapped position
         CapturedImage.ScaleTo(MAX_SCALE, 250, Easing.CubicInOut);
     }
 }
Exemplo n.º 5
0
        private void captureButton_MouseDown(object sender, MouseButtonEventArgs e)
        {
            if (currentMode == 0)
            {
                if ((DateTime.Now - lastImageTaken).TotalMilliseconds > 200)
                {
                    lastImageTaken = DateTime.Now;

                    BitmapSource captureImage = (BitmapSource)webcamImage.Source;

                    /*CapturedImage.Source = BitmapImage.Create(
                     *  2,
                     *  2,
                     *  96,
                     *  96,
                     *  PixelFormats.Indexed1,
                     *  new BitmapPalette(new List<Color> { Colors.Transparent }),
                     *  new byte[] { 0, 0, 0, 0 },
                     *  1);*/
                    CapturedImage.Source = captureImage;

                    CapturedImage.Width   = captureImage.Width;
                    CapturedImage.Height  = captureImage.Height;
                    CapturedImage.Opacity = 1;

                    /*DoubleAnimation da = new DoubleAnimation();
                     * da.From = videoSource.VideoResolution.FrameSize.Height;
                     * da.To = new Thickness(100);
                     * da.Duration = new Duration(TimeSpan.FromSeconds(0.15F));
                     * */

                    //da.RepeatBehavior=new RepeatBehavior(3);
                    DoubleAnimation ta = new DoubleAnimation();
                    ta.From       = captureImage.Height;
                    ta.To         = 0;
                    ta.Duration   = new Duration(TimeSpan.FromSeconds(0.3F));
                    ta.Completed += ta_Completed;

                    CapturedImage.BeginAnimation(HeightProperty, ta);

                    DoubleAnimation da = new DoubleAnimation();
                    da.From     = 1;
                    da.To       = 0;
                    da.Duration = new Duration(TimeSpan.FromSeconds(0.2F));

                    CapturedImage.BeginAnimation(OpacityProperty, da);

                    WriteJpeg(GetFileName("Picture", ".jpeg"), 100, (BitmapSource)captureImage, Environment.GetFolderPath(Environment.SpecialFolder.MyPictures));
                }
            }
            else if (currentMode == 1)
            {
                if (isRecording)
                {
                    StopRecording();
                }
                else
                {
                    StartRecording();
                }
            }
        }
Exemplo n.º 6
0
    private CapturedImage TakeSnapshotNow(Shader targetShader, string outputFormat = "use_preferred_output_format")
    {
        if(DEBUG)
        {
            Debug.Log("NAME SHADER");
            if (targetShader != null)
            { Debug.Log(targetShader.name); }
        }

        if (DEBUG && NetMessenger.logTimingInfo)
            Debug.LogFormat("Start TakeShapshotNow() {0} {1}", (targetShader == null) ? "(null)" : targetShader.name, Utils.GetTimeStamp());
        // Create a new camera if we need to that we will be manually rendering
        if (_textureCam == null)
        {
            if(DEBUG)
                Debug.Log ("Texture cam is null");

            GameObject newObj = new GameObject("Texture-Writing Camera");
            _textureCam = newObj.AddComponent<Camera>();
            _textureCam.enabled = false;
            _textureCam.targetTexture = new RenderTexture(targetCam.pixelWidth, targetCam.pixelHeight, 0, RenderTextureFormat.ARGB32);

            // Image Effects
            if (true && targetCam != null)
            {
                targetCam.hdr = true;

                // Tone Mapping
                targetCam.gameObject.AddComponent<TonemappingColorGrading>();
                var tonemapping = targetCam.gameObject.GetComponent<TonemappingColorGrading>().tonemapping; //ToneMappingSettings
                tonemapping.enabled = true;
                tonemapping.exposure = 2;
                tonemapping.tonemapper = TonemappingColorGrading.Tonemapper.Photographic;
                targetCam.gameObject.GetComponent<TonemappingColorGrading>().tonemapping = tonemapping;

                // Eye Adaptation
                var eyeadaptation = targetCam.gameObject.GetComponent<TonemappingColorGrading>().eyeAdaptation; //EyeAdaptationSettings
                eyeadaptation.enabled = true;
                targetCam.gameObject.GetComponent<TonemappingColorGrading>().eyeAdaptation = eyeadaptation;

                // Depth of Field
                targetCam.gameObject.AddComponent<DepthOfField>();

                //Ambient Occlusion
                targetCam.gameObject.AddComponent<AmbientOcclusion>();

                //Screen Space Reflections
                targetCam.renderingPath = RenderingPath.DeferredShading;
                targetCam.gameObject.AddComponent<ScreenSpaceReflection>();
            }

            if (testImage != null)
                testImage.texture = _textureCam.targetTexture;
        }

        // Call render with the appropriate shaders
        if (targetShader != null)
        {
            RenderTexture.active = shaderCam.targetTexture;
            shaderCam.RenderWithShader(targetShader, null);
        }
        else
        {
            RenderTexture.active = targetCam.targetTexture;
            targetCam.Render();
        }
        if (DEBUG && NetMessenger.logTimingInfo)
            Debug.LogFormat("  Finished Rendering {0}", Utils.GetTimeStamp());

        // Copy and convert rendered image to PNG format as a byte array
        const bool SHOULD_USE_MIPMAPS = false;
        int pixWidth = _textureCam.targetTexture.width;
        int pixHeight = _textureCam.targetTexture.height;

        if (_outPhoto == null || _outPhoto.width != pixWidth || _outPhoto.height != pixHeight)
            _outPhoto = new Texture2D(pixWidth, pixHeight, TextureFormat.ARGB32, SHOULD_USE_MIPMAPS);

        _outPhoto.ReadPixels(new Rect(0, 0, pixWidth, pixHeight), 0, 0);
        _outPhoto.Apply();

        if (DEBUG && NetMessenger.logTimingInfo)
            Debug.LogFormat("  Created texture(internal format) {0}", Utils.GetTimeStamp());

        CapturedImage retImage = new CapturedImage();

        if(outputFormat == "use_preferred_output_format")
        {
            if (preferredImageFormat == "png")
                retImage.pictureBuffer = _outPhoto.EncodeToPNG();
            else if (preferredImageFormat == "jpg")
                retImage.pictureBuffer = _outPhoto.EncodeToJPG();
            else
                EncodeBMP(ref retImage, _outPhoto, pixWidth, pixHeight);
        }
        else if (outputFormat == "png")
            retImage.pictureBuffer = _outPhoto.EncodeToPNG();
        else if (outputFormat == "jpg")
            retImage.pictureBuffer = _outPhoto.EncodeToJPG();
        else
            EncodeBMP(ref retImage, _outPhoto, pixWidth, pixHeight);

        if (NetMessenger.logTimingInfo)
            Debug.LogFormat("  Encoded image {0}", Utils.GetTimeStamp());

        return retImage;
    }
Exemplo n.º 7
0
 private static void EncodeBMP(ref CapturedImage imgData, Texture2D textureSrc, int width, int height)
 {
     // Write out BMP file
     UpdateBMPHeader((UInt32)width, (UInt32)height);
     int byteArrayLength = _bmpHeader.Length + width * height * 4;
     Color32[] pixels = textureSrc.GetPixels32();
     if (imgData.pictureBuffer == null || imgData.pictureBuffer.Length != byteArrayLength)
         imgData.pictureBuffer = new byte[byteArrayLength];
     int byteIndex = 0;
     System.Buffer.BlockCopy(_bmpHeader, 0, imgData.pictureBuffer, 0, _bmpHeader.Length);
     for(int i = 0; i < pixels.Length; ++i)
     {
         byteIndex = 4*i + _bmpHeader.Length;
         imgData.pictureBuffer[byteIndex+0] = pixels[i].a;
         imgData.pictureBuffer[byteIndex+1] = pixels[i].b;
         imgData.pictureBuffer[byteIndex+2] = pixels[i].g;
         imgData.pictureBuffer[byteIndex+3] = pixels[i].r;
     }
 }
Exemplo n.º 8
0
    private CapturedImage TakeSnapshotNow(Shader targetShader)
    {
        if (NetMessenger.logTimingInfo)
            Debug.LogFormat("Start TakeShapshotNow() {0} {1}", (targetShader == null) ? "(null)" : targetShader.name, Utils.GetTimeStamp());
        // Create a new camera if we need to that we will be manually rendering
        if (_textureCam == null)
        {
            Debug.Log ("Texture cam is null");
            GameObject newObj = new GameObject("Texture-Writing Camera");
            _textureCam = newObj.AddComponent<Camera>();
            _textureCam.enabled = false;
            _textureCam.targetTexture = new RenderTexture(targetCam.pixelWidth, targetCam.pixelHeight, 0, RenderTextureFormat.ARGB32);
            if (testImage != null)
                testImage.texture = _textureCam.targetTexture;
        }

        // Call render with the appropriate shaders
        if (targetShader != null)
            targetCam.RenderWithShader(targetShader, null);
        else
            targetCam.Render();
        if (NetMessenger.logTimingInfo)
            Debug.LogFormat("  Finished Rendering {0}", Utils.GetTimeStamp());

        // Copy and convert rendered image to PNG format as a byte array
        const bool SHOULD_USE_MIPMAPS = false;
        int pixWidth = _textureCam.targetTexture.width;
        int pixHeight = _textureCam.targetTexture.height;

        if (_outPhoto == null || _outPhoto.width != pixWidth || _outPhoto.height != pixHeight)
            _outPhoto = new Texture2D(pixWidth, pixHeight, TextureFormat.ARGB32, SHOULD_USE_MIPMAPS);

        //Debug.Log ("pW: " + pixWidth + ", pH: " + pixHeight + ", opW: " + _outPhoto.width + ", opH" + _outPhoto.height);

        _outPhoto.ReadPixels(new Rect(0, 0, pixWidth, pixHeight), 0, 0);
        _outPhoto.Apply();

        if (NetMessenger.logTimingInfo)
            Debug.LogFormat("  Created texture(internal format) {0}", Utils.GetTimeStamp());

        CapturedImage retImage = new CapturedImage();
        if (preferredImageFormat == "png")
            retImage.pictureBuffer = _outPhoto.EncodeToPNG();
        else if (preferredImageFormat == "jpg")
            retImage.pictureBuffer = _outPhoto.EncodeToJPG();
        else
            EncodeBMP(ref retImage, _outPhoto, pixWidth, pixHeight);
        if (NetMessenger.logTimingInfo)
            Debug.LogFormat("  Encoded image {0}", Utils.GetTimeStamp());
        return retImage;
    }