Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7684241
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 31, 20262026-05-31T18:58:52+00:00 2026-05-31T18:58:52+00:00

I am trying to apply image manipulation effects in Windows 8 app on camera

  • 0

I am trying to apply image manipulation effects in Windows 8 app on camera feeds directly.
I have tried a way using canvas and redrawing images after applying effects getting from webcam directly. But this approach works fine for basic effects but for effects like edge detection its creating large lag and flickering while using canvas approach.

Other way is to create MFT(media foundation transform) but it can be implemented in C about which i have no idea.

Can anyone tell me how can i achieve my purpose of applying effects on webcam stream directly in Windows 8 metro style app either by improving canvas approach so that large effects like edge detection don not have any issues or how can i apply MFT in C# since i have worked on C# language or by some other approach?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-31T18:58:54+00:00Added an answer on May 31, 2026 at 6:58 pm

    I have just played quite a bit in this area the last week and even considered writing a blog post about it. I guess this answer can be just as good.

    You can go the MFT way, which needs to be done in C++, but the things you would need to write would not be much different between C# and C++. The only thing of note is that I think the MFT works in YUV color space, so your typical convolution filters/effects might behave a bit differently or require conversion to RGB. If you decide to go that route On the C# application side the only thing you would need to do is to call MediaCapture.AddEffectAsync(). Well that and you need to edit your Package.appxmanifest etc., but let’s go with first things first.

    If you look at the Media capture using webcam sample – it already does what you need. It applies a grayscale effect to your camera feed. It includes a C++ MFT project that is used in an application that is available in C# version. I had to apply the effect to a MediaElement which might not be what you need, but is just as simple – call MediaElement.AddVideoEffect() and your video file playback now applies the grayscale effect. To be able to use the MFT – you need to simply add a reference to the GrayscaleTransform project and add following lines to your appxmanifest:

    <Extensions>
      <Extension Category="windows.activatableClass.inProcessServer">
        <InProcessServer>
          <Path>GrayscaleTransform.dll</Path>
          <ActivatableClass ActivatableClassId="GrayscaleTransform.GrayscaleEffect" ThreadingModel="both" />
        </InProcessServer>
      </Extension>
    </Extensions>
    

    How the MFT code works:

    The following lines create a pixel color transformation matrix

    float scale = (float)MFGetAttributeDouble(m_pAttributes, MFT_GRAYSCALE_SATURATION, 0.0f);
    float angle = (float)MFGetAttributeDouble(m_pAttributes, MFT_GRAYSCALE_CHROMA_ROTATION, 0.0f);
    m_transform = D2D1::Matrix3x2F::Scale(scale, scale) * D2D1::Matrix3x2F::Rotation(angle);
    

    Depending on the pixel format of the video feed – a different transformation method is selected to scan the pixels. Look for these lines:

    m_pTransformFn = TransformImage_YUY2;
    m_pTransformFn = TransformImage_UYVY;
    m_pTransformFn = TransformImage_NV12;
    

    For my sample m4v file – the format is detected as NV12, so it is calling TransformImage_NV12.

    For pixels within the specified range (m_rcDest) or within the entire screen if no range was specified – the TransformImage_~ methods call TransformChroma(mat, &u, &v).
    For other pixels – the values from original frame are copied.

    TransformChroma transforms the pixels using m_transform. If you want to change the effect – you can simply change the m_transform matrix or if you need access to neighboring pixels as in an edge detection filter – modify the TransformImage_ methods to process these pixels.

    This is one way to do it. I think it is quite CPU intensive, so personally I prefer to write a pixel shader for such operations. How do you apply a pixel shader to a video stream though? Well, I am not quite there yet, but I believe you can transfer video frames to a DirectX surface fairly easily and call a pixel shader on them later. So far – I was able to transfer the video frames and I am hoping to apply the shaders next week. I might write a blog post about it. I took the meplayer class from the Media engine native C++ playback sample and moved it to a template C++ DirectX project converted to a WinRTComponent library, then used it with a C#/XAML application, associating the swapchain the meplayer class creates with the SwapChainBackgroundPanel that I use in the C# project to display the video. I had to make a few changes in the meplayer class. First – I had to move it to a public namespace that would make it available to other assembly. Then I had to modify the swapchain it creates to a format accepted for use with a SwapChainBackgroundPanel:

            DXGI_SWAP_CHAIN_DESC1 swapChainDesc = {0};
            swapChainDesc.Width = m_rcTarget.right;
            swapChainDesc.Height = m_rcTarget.bottom;
            // Most common swapchain format is DXGI_FORMAT_R8G8B8A8-UNORM
            swapChainDesc.Format = m_d3dFormat;
            swapChainDesc.Stereo = false;
    
            // Don't use Multi-sampling
            swapChainDesc.SampleDesc.Count = 1;
            swapChainDesc.SampleDesc.Quality = 0;
    
            //swapChainDesc.BufferUsage = DXGI_USAGE_BACK_BUFFER | DXGI_USAGE_RENDER_TARGET_OUTPUT;
            swapChainDesc.BufferUsage = DXGI_USAGE_RENDER_TARGET_OUTPUT; // Allow it to be used as a render target.
            // Use more than 1 buffer to enable Flip effect.
            //swapChainDesc.BufferCount = 4;
            swapChainDesc.BufferCount = 2;
            //swapChainDesc.Scaling = DXGI_SCALING_NONE;
            swapChainDesc.Scaling = DXGI_SCALING_STRETCH;
            swapChainDesc.SwapEffect = DXGI_SWAP_EFFECT_FLIP_SEQUENTIAL;
            swapChainDesc.Flags = 0;
    

    Finally – instead of calling CreateSwapChainForCoreWindow – I am calling CreateSwapChainForComposition and associating the swapchain with my SwapChainBackgroundPanel:

            // Create the swap chain and then associate it with the SwapChainBackgroundPanel.
            DX::ThrowIfFailed(
                spDXGIFactory.Get()->CreateSwapChainForComposition(
                    spDevice.Get(),
                    &swapChainDesc,
                    nullptr,                                // allow on all displays
                    &m_spDX11SwapChain)
                );
    
            ComPtr<ISwapChainBackgroundPanelNative> dxRootPanelAsSwapChainBackgroundPanel;
    
            // Set the swap chain on the SwapChainBackgroundPanel.
            reinterpret_cast<IUnknown*>(m_swapChainPanel)->QueryInterface(
                IID_PPV_ARGS(&dxRootPanelAsSwapChainBackgroundPanel)
                );
    
            DX::ThrowIfFailed(
                dxRootPanelAsSwapChainBackgroundPanel->SetSwapChain(m_spDX11SwapChain.Get())
                );
    

    *EDIT follows

    Forgot about one more thing. If your goal is to stay in pure C# – if you figure out how to capture frames to a WriteableBitmap (maybe by calling MediaCapture.CapturePhotoToStreamAsync() with a MemoryStream and then calling WriteableBitmap.SetSource() on the stream) – you can use WriteableBitmapEx to process your images. It might not be top performance, but if your resolution is not too high or your frame-rate requirements are not high – it might just be enough. The project on CodePlex does not officially support WinRT yet, but I have a version that should work that you can try here (Dropbox).

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am trying to apply effect (sepia, brightness, bloom and other image effects if
I am trying to apply brightness/contrast on a image using track bar, since applying
I'm trying to apply BlendModes to a GreyScale image in order to have reusable
I am trying to apply some transformations on images using a CGContextRef. I am
I am trying to apply a method to an existing object which involves using
I have a list of 179 thumbnail images that I am trying to apply
I'm trying to fetch and apply an artist image from Last.fm to an ImageView
I have a bitmap, and I am trying to apply an alpha channel to
I'm trying to draw grayscale image in color as texture in OpenGL using two
I'm trying to apply CSS3 image-resolution property on my image but it has no

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.