Solved

How to capture a image in WPF application

Posted on 2013-06-25
6
470 Views
Last Modified: 2013-07-20
Hi,
I have WPF application created using .Net 4.0 and VS 2010.
I want to capture the image from the WPF  application.

Please help me in moving the right direction.

Thanks.
0
Comment
Question by:KavyaVS
  • 3
  • 2
6 Comments
 
LVL 42

Assisted Solution

by:sedgwick
sedgwick earned 50 total points
ID: 39277817
what do u mean capture the image?
screenshot of the application?
0
 
LVL 13

Assisted Solution

by:jonnidip
jonnidip earned 450 total points
ID: 39277900
If the meaning of your question is "capturing a screenshot of the application" (as previous comment), then you may use this function:
private static void CaptureScreen()
{
    String FileName = @"c:\temp\screenshot.jpg";
    using (Bitmap screenBmp = new Bitmap((Int32)SystemParameters.PrimaryScreenWidth,
                                            (Int32)SystemParameters.PrimaryScreenHeight,
                                            System.Drawing.Imaging.PixelFormat.Format32bppArgb))
    {
        using (Graphics bmpGraphics = Graphics.FromImage(screenBmp))
        {
            bmpGraphics.CopyFromScreen(0, 0, 0, 0, screenBmp.Size);
            BitmapSource bmpSource = Imaging.CreateBitmapSourceFromHBitmap(
                                                screenBmp.GetHbitmap(),
                                                IntPtr.Zero,
                                                Int32Rect.Empty,
                                                BitmapSizeOptions.FromEmptyOptions());
            BitmapEncoder bmpEncoder = new JpegBitmapEncoder() { QualityLevel = 20 };
            bmpEncoder.Frames.Add(BitmapFrame.Create(bmpSource));
            using (FileStream fs = new FileStream(FileName, FileMode.Create))
                bmpEncoder.Save(fs);
        }
    }
}

Open in new window


Regards.
0
 

Author Comment

by:KavyaVS
ID: 39278475
It is not capturing the screen shot of the application.It is capturing the image from web cam
or camera.

Thanks.
0
DevOps Toolchain Recommendations

Read this Gartner Research Note and discover how your IT organization can automate and optimize DevOps processes using a toolchain architecture.

 
LVL 13

Accepted Solution

by:
jonnidip earned 450 total points
ID: 39278753
In that case, you will need to enumerate your devices using WIA or WPD (for Vista and later).
In the past I used to develop code for both Twain and WIA, but I preferred to buy a 3rd party component (sorry, can't remember the name).
You may check here for a modern solution.

I hope this can help.

Regards.
0
 

Author Comment

by:KavyaVS
ID: 39278913
I tried the example in codeplex. But I am not sure what else I need to added and how it will work. Please check this http://easywebcam.codeplex.com/

It is compiling but not working.Please let me know what else I need to add for the above example I used. I am testing it in Windows 7.


Thanks
0
 

Author Closing Comment

by:KavyaVS
ID: 39342055
Thanks
0

Featured Post

3 Use Cases for Connected Systems

Our Dev teams are like yours. They’re continually cranking out code for new features/bugs fixes, testing, deploying, testing some more, responding to production monitoring events and more. It’s complex. So, we thought you’d like to see what’s working for us.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Problem Hi all,    While many today have fast Internet connection, there are many still who do not, or are connecting through devices with a slower connect, so light web pages and fast load times are still popular.    If your ASP.NET page …
This article aims to explain the working of CircularLogArchiver. This tool was designed to solve the buildup of log file in cases where systems do not support circular logging or where circular logging is not enabled
Established in 1997, Technology Architects has become one of the most reputable technology solutions companies in the country. TA have been providing businesses with cost effective state-of-the-art solutions and unparalleled service that is designed…
With Secure Portal Encryption, the recipient is sent a link to their email address directing them to the email laundry delivery page. From there, the recipient will be required to enter a user name and password to enter the page. Once the recipient …

770 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question