Solved

How to capture a image in WPF application

Posted on 2013-06-25
6
477 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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
PeopleSoft Has Never Been Easier

PeopleSoft Adoption Made Smooth & Simple!

On-The-Job Training Is made Intuitive & Easy With WalkMe's On-Screen Guidance Tool.  Claim Your Free WalkMe Account Now

 
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

Quiz: What Do These Organizations Have In Common?

Hint: Their teams ended up taking quizzes, too.

Question has a verified solution.

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

ASP.Net to Oracle Connectivity Recently I had to develop an ASP.NET application connecting to an Oracle database.As I am doing it first time ,I had to solve several problems. This article will help to such developers  to develop an ASP.NET client…
Calculating holidays and working days is a function that is often needed yet it is not one found within the Framework. This article presents one approach to building a working-day calculator for use in .NET.
Michael from AdRem Software outlines event notifications and Automatic Corrective Actions in network monitoring. Automatic Corrective Actions are scripts, which can automatically run upon discovery of a certain undesirable condition in your network.…
Monitoring a network: how to monitor network services and why? Michael Kulchisky, MCSE, MCSA, MCP, VTSP, VSP, CCSP outlines the philosophy behind service monitoring and why a handshake validation is critical in network monitoring. Software utilized …

724 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