Solved

How to capture a image in WPF application

Posted on 2013-06-25
6
467 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
IT, Stop Being Called Into Every Meeting

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

 
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

Find Ransomware Secrets With All-Source Analysis

Ransomware has become a major concern for organizations; its prevalence has grown due to past successes achieved by threat actors. While each ransomware variant is different, we’ve seen some common tactics and trends used among the authors of the malware.

Join & Write a Comment

A long time ago (May 2011), I have written an article showing you how to create a DLL using Visual Studio 2005 to be hosted in SQL Server 2005. That was valid at that time and it is still valid if you are still using these versions. You can still re…
International Data Corporation (IDC) prognosticates that before the current the year gets over disbursing on IT framework products to be sent in cloud environs will be $37.1B.
Excel styles will make formatting consistent and let you apply and change formatting faster. In this tutorial, you'll learn how to use Excel's built-in styles, how to modify styles, and how to create your own. You'll also learn how to use your custo…
This video demonstrates how to create an example email signature rule for a department in a company using CodeTwo Exchange Rules. The signature will be inserted beneath users' latest emails in conversations and will be displayed in users' Sent Items…

747 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

Need Help in Real-Time?

Connect with top rated Experts

12 Experts available now in Live!

Get 1:1 Help Now