Solved

How to capture a image in WPF application

Posted on 2013-06-25
6
472 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
How Do You Stack Up Against Your Peers?

With today’s modern enterprise so dependent on digital infrastructures, the impact of major incidents has increased dramatically. Grab the report now to gain insight into how your organization ranks against your peers and learn best-in-class strategies to resolve incidents.

 
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

Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
disable data migrations in visual studio 2017 4 49
Problem to copy file 14 52
SSIS GUID Variable 2 37
c#, case, if 4 19
Just a quick little trick I learned recently.  Now that I'm using jQuery with abandon in my asp.net applications, I have grown tired of the following syntax:      (CODE) I suppose it just offends my sense of decency to put inline VBScript on a…
Today I had a very interesting conundrum that had to get solved quickly. Needless to say, it wasn't resolved quickly because when we needed it we were very rushed, but as soon as the conference call was over and I took a step back I saw the correct …
In an interesting question (https://www.experts-exchange.com/questions/29008360/) here at Experts Exchange, a member asked how to split a single image into multiple images. The primary usage for this is to place many photographs on a flatbed scanner…

733 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