Click here to Skip to main content
15,888,189 members
Please Sign up or sign in to vote.
1.00/5 (2 votes)
See more:
Is there any Screen Capture class for WPF that allows you to capture Whole Specified Rectangle ?

Please in VB

[Edit - OPs code from comment]
I found on the internet :
C#
private static BitmapSource CopyScreen()
    {
        using (var screenBmp = new Bitmap(
            (int)SystemParameters.PrimaryScreenWidth,
            (int)SystemParameters.PrimaryScreenHeight,
            PixelFormat.Format32bppArgb))
        {
            using (var bmpGraphics = Graphics.FromImage(screenBmp))
            {
                bmpGraphics.CopyFromScreen(0, 0, 0, 0, screenBmp.Size);
                return Imaging.CreateBitmapSourceFromHBitmap(
                    screenBmp.GetHbitmap(),
                    IntPtr.Zero,
                    Int32Rect.Empty,
                    BitmapSizeOptions.FromEmptyOptions());
            }
        }
    }

But I can't read this.
Posted
Updated 23-Sep-13 10:08am
v3
Comments
CHill60 23-Sep-13 15:59pm    
What have you tried so far?
quator 23-Sep-13 16:02pm    
I found on the internet :

private static BitmapSource CopyScreen()
{
using (var screenBmp = new Bitmap(
(int)SystemParameters.PrimaryScreenWidth,
(int)SystemParameters.PrimaryScreenHeight,
PixelFormat.Format32bppArgb))
{
using (var bmpGraphics = Graphics.FromImage(screenBmp))
{
bmpGraphics.CopyFromScreen(0, 0, 0, 0, screenBmp.Size);
return Imaging.CreateBitmapSourceFromHBitmap(
screenBmp.GetHbitmap(),
IntPtr.Zero,
Int32Rect.Empty,
BitmapSizeOptions.FromEmptyOptions());
}
}
}

But I can't read this.
quator 23-Sep-13 16:09pm    
I have four regtangles red, blue, green en yellow. The rectangle form the screen i like that compare with this 4 rectangles.
CHill60 23-Sep-13 16:18pm    
I think this is the same code in VB.NET ...does that help?
Private Shared Function CopyScreen() As BitmapSource
Dim screenBMP As Bitmap
screenBMP = New Bitmap(CInt(SystemParameters.PrimaryScreenWidth), CInt(SystemParameters.PrimaryScreenHeight), PixelFormat.Format32bppArgb)
Using screenBMP
Using bmpGraphics = Graphics.FromImage(screenBMP)
bmpGraphics.CopyFromScreen(0, 0, 0, 0, screenBMP.Size)
Return Imaging.CreateBitmapSourceFromHBitmap(screenBMP.GetHbitmap(), IntPtr.Zero, Int32Rect.Empty, BitmapSizeOptions.FromEmptyOptions())
End Using
End Using
End Function
quator 24-Sep-13 3:22am    
Tonight I will try

1 solution

See, for example: http://sourceforge.net/projects/screencapturewp/[^].

As this is an open-code code, you can always see how it works.

See also this CodeProject article: Screen Capture in WPF & WinForms Application[^].

The problem is actually pretty simple. You can find a lot more: http://bit.ly/19y71d6[^].

—SA
 
Share this answer
 
Comments
quator 24-Sep-13 3:21am    
Tonight I will try
Sergey Alexandrovich Kryukov 24-Sep-13 8:55am    
Great.
—SA
CHill60 24-Sep-13 8:18am    
My 5. I particularly like the comprehensive information available on the final link :-)
Sergey Alexandrovich Kryukov 24-Sep-13 8:56am    
Thank you.
—SA

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900