Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

How to capture a image in WPF application

Posted on 2013-06-25
6
Medium Priority
?
487 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:Meir Rivkin
Meir Rivkin earned 150 total points
ID: 39277817
what do u mean capture the image?
screenshot of the application?
0
 
LVL 13

Assisted Solution

by:jonnidip
jonnidip earned 1350 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
Windows Server 2016: All you need to know

Learn about Hyper-V features that increase functionality and usability of Microsoft Windows Server 2016. Also, throughout this eBook, you’ll find some basic PowerShell examples that will help you leverage the scripts in your environments!

 
LVL 13

Accepted Solution

by:
jonnidip earned 1350 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

Tech or Treat! - Giveaway

Submit an article about your scariest tech experience—and the solution—and you’ll be automatically entered to win one of 4 fantastic tech gadgets.

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…
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 …
In this video, Percona Solutions Engineer Barrett Chambers discusses some of the basic syntax differences between MySQL and MongoDB. To learn more check out our webinar on MongoDB administration for MySQL DBA: https://www.percona.com/resources/we…
Are you ready to place your question in front of subject-matter experts for more timely responses? With the release of Priority Question, Premium Members, Team Accounts and Qualified Experts can now identify the emergent level of their issue, signal…

604 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