[phpBB Debug] PHP Notice: in file /viewtopic.php on line 1506: Undefined offset: 18902
[phpBB Debug] PHP Notice: in file /includes/functions.php on line 4284: Cannot modify header information - headers already sent by (output started at /includes/functions.php:3493)
[phpBB Debug] PHP Notice: in file /includes/functions.php on line 4286: Cannot modify header information - headers already sent by (output started at /includes/functions.php:3493)
[phpBB Debug] PHP Notice: in file /includes/functions.php on line 4287: Cannot modify header information - headers already sent by (output started at /includes/functions.php:3493)
[phpBB Debug] PHP Notice: in file /includes/functions.php on line 4288: Cannot modify header information - headers already sent by (output started at /includes/functions.php:3493)
Конференция VBStreets • Просмотр темы — [RESOLVED] GetDC и сохранение скриншота в PictureBox
Страница 1 из 1

[RESOLVED] GetDC и сохранение скриншота в PictureBox

СообщениеДобавлено: 20.01.2009 (Вт) 22:57
NeverGone
Нужно сделать скриншот экрана КПК и загрузить его в PictureBox (потом он будет масштабироваться).
Как его получить? GetDC ? Как получить "снятую" им картинку?
Подскажите, пожалуйста. Желательно примерчиком. Ну или ссылку на подобный проект, если таковые есть.
Заранее спасибо!

Re: GetDC и сохранение скриншота в PictureBox

СообщениеДобавлено: 16.02.2009 (Пн) 15:37
NeverGone
Ну что же опять молчание? :|
Может быть, можно обойтись без GetDC?
Нашел вот такое:
Код: Выделить всё
    Private Declare Sub keybd_event Lib "coredll.dll" (ByVal bVk As Byte, ByVal bScan As Byte, ByVal dwFlags As Integer, ByVal dwExtraInfo As Integer)
    Private Const VK_SNAPSHOT As Short = &H2CS

    Private Sub Command2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Command2.Click
        Call keybd_event(System.Windows.Forms.Keys.Snapshot, 0, 0, 0)
        System.Threading.Thread.Sleep(200) ' To have time to catch the clipboard
        Dim data As IDataObject
        data = Clipboard.GetDataObject()
        Dim bmap As Bitmap
        If data.GetDataPresent(GetType(System.Drawing.Bitmap)) Then
            bmap = CType(data.GetData(GetType(System.Drawing.Bitmap)), Bitmap)
            Me.PictureBox1.Image = bmap
        End If
    End Sub

Но данный код не выводит в PictureBox ничего.
Как можно получить скриншот?

Re: GetDC и сохранение скриншота в PictureBox

СообщениеДобавлено: 27.01.2010 (Ср) 14:57
NeverGone
ВНЕЗАПНО ( :mrgreen: ) проблема стала опять актуальна.
Подскажите хоть, в каком направлении думать... :oops:

Re: GetDC и сохранение скриншота в PictureBox

СообщениеДобавлено: 09.02.2010 (Вт) 21:38
Lotreck
Код: Выделить всё
Option Explicit On
Imports System.IO
Imports System.Drawing.Drawing2D
Imports System.Windows.Forms
Imports System.Runtime.InteropServices
Imports Microsoft.WindowsCE.Forms
Imports System.Data

Public Class Form1
    Public Structure RECT
        Public Left As Int32
        Public Top As Int32
        Public Right As Int32
        Public Bottom As Int32
    End Structure
   
    Private Const SRCCOPY = &HCC0020
    Declare Function GetWindowRect Lib "coredll.dll" (ByVal hWnd As IntPtr, ByRef lpRect As RECT) As Boolean
    Declare Function GetDesktopWindow Lib "coredll.dll" () As IntPtr
    Declare Function GetWindowDC Lib "coredll.dll" (ByVal hwnd As IntPtr) As IntPtr
    Declare Function GetDC Lib "coredll.dll" (ByVal hWnd As IntPtr) As IntPtr
    Declare Function ReleaseDC Lib "coredll.dll" (ByVal hWnd As IntPtr, ByVal hDC As IntPtr) As IntPtr
    Declare Function BitBlt Lib "coredll.dll" ( _
    ByVal hdcDest As IntPtr, _
    ByVal nXDest As Integer, _
    ByVal nYDest As Integer, _
    ByVal nWidth As Integer, _
    ByVal nHeight As Integer, _
    ByVal hdcSrc As IntPtr, _
    ByVal nXSrc As Integer, _
    ByVal nYSrc As Integer, _
    ByVal dwRop As Int32) As Integer
    'скриншот экрана
    Private Sub Button1_Click_1(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
        'Dim rect As New Rectangle(0, 0, Screen.PrimaryScreen.Bounds.Width, Screen.PrimaryScreen.Bounds.Height)
        Dim rct As New Rectangle(0, -26, Screen.PrimaryScreen.Bounds.Width, Screen.PrimaryScreen.Bounds.Height)
        Dim bmp As New Bitmap(rct.Width, rct.Height)
        Dim gfx As Graphics = Graphics.FromImage(bmp)
        Dim hwnd As IntPtr = GetDesktopWindow()
        Dim hdc As IntPtr = GetDC(hwnd)
        BitBlt(gfx.GetHdc(), 0, 0, rct.Width, rct.Height, hdc, rct.Left, rct.Top, SRCCOPY)
        bmp.Save("\Storage Card\1.bmp", System.Drawing.Imaging.ImageFormat.Bmp)
        ReleaseDC(hwnd, hdc)
        gfx.Dispose()
        PictureBox1.Image = bmp
    End Sub
    'скриншот экрана
    Private Sub Button2_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles Button2.Click
        Dim hWndDesktop As IntPtr = GetDesktopWindow()
        Dim rct As RECT
        GetWindowRect(hWndDesktop, rct)
        rct.Top = 0
        Dim Width As Int32 = rct.Right - rct.Left
        Dim Height As Int32 = rct.Bottom - rct.Top
        Dim bmp As New Bitmap(Width, Height)
        Dim gfx As Graphics = Graphics.FromImage(bmp)
        Dim hdcWindow As IntPtr = GetDC(hWndDesktop)
        Dim hdc As IntPtr = gfx.GetHdc()
        'BitBlt(hdc.ToInt32, 0, 0, Width, Height, hdcWindow.ToInt32, rct.Left, rct.Top, SRCCOPY)
        BitBlt(hdc.ToInt32, 0, 0, Width, Height, hdcWindow.ToInt32, rct.Left, rct.Top - 26, SRCCOPY)
        bmp.Save("\Storage Card\2.bmp", System.Drawing.Imaging.ImageFormat.Bmp)
        ReleaseDC(hWndDesktop, hdcWindow)
        gfx.ReleaseHdc(hdc)
        PictureBox1.Image = bmp
    End Sub
    'скриншот контрола
    Private Sub Button3_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles Button3.Click
        Dim Cntr As Control
        'Cntr = Me
        Cntr = Button2
        Dim bmp As Bitmap = New Bitmap(Cntr.Width, Cntr.Height)
        Dim cForm As IntPtr = Cntr.Handle
        Dim gfx As Graphics = Graphics.FromImage(bmp)
        Dim hdcScreen As IntPtr = GetWindowDC(cForm)
        Dim hdc As IntPtr = gfx.GetHdc()
        BitBlt(hdc, 0, 0, Cntr.Width, Cntr.Height, hdcScreen, Cntr.Location.X, Cntr.Location.Y, SRCCOPY)
        gfx.ReleaseHdc(hdc)
        ReleaseDC(IntPtr.Zero, hdcScreen)
        bmp.Save("\Storage Card\3.bmp", Drawing.Imaging.ImageFormat.Bmp)
        PictureBox1.Image = bmp
    End Sub
End Class

Re: GetDC и сохранение скриншота в PictureBox

СообщениеДобавлено: 14.02.2010 (Вс) 11:35
NeverGone
ДДААА!!11 :D
Спасибо огромное!

Re: GetDC и сохранение скриншота в PictureBox

СообщениеДобавлено: 14.02.2010 (Вс) 17:06
Lotreck
Почитай "Занимательное программирование на Visual Basic .Net" Климова, там расписано в подробностях.