Título: Capturar contenido en un Picturebox
Publicado por: Brian1511 en 15 Enero 2015, 04:01 am
Bueno como dice el titulo solo quiero saber si es posible capturar lo que este dentro de un picturebox, al decir capturar es tirar un screenshot dentro de los objetos que esten en el picturebox es decir un ejemplo mas grafico:
(http://i38.servimg.com/u/f38/17/14/00/00/hh10.png)
Quisiera hacer una captura a todo lo que este en su interior, pero en forma de imagen ;)
Gracias de antemano! Un saludo!
Título: Re: Capturar contenido en un Picturebox
Publicado por: LeandroA en 15 Enero 2015, 18:42 pm
Hola casualmente alguien pregunto en otro foro lo mismo pero con zoom, aca tenes una rutina en un modulo Option Explicit Private Type GUID Data1 As Long Data2 As Integer Data3 As Integer Data4(7) As Byte End Type Private Type PicBmp Size As Long Type As Long hBmp As Long hPal As Long Reserved As Long End Type Private Type RECT Left As Long Top As Long Right As Long Bottom As Long End Type Private Declare Function GetDC Lib "user32.dll" (ByVal hwnd As Long) As Long Private Declare Function ReleaseDC Lib "user32.dll" (ByVal hwnd As Long, ByVal hdc As Long) As Long Private Declare Function PrintWindow Lib "user32.dll" (ByVal hwnd As Long, ByVal hdcBlt As Long, ByVal nFlags As Long) As Long Private Declare Function OleCreatePictureIndirect Lib "olepro32.dll" (PicDesc As PicBmp, RefIID As GUID, ByVal fPictureOwnsHandle As Long, IPic As IPicture) As Long Private Declare Function CreateCompatibleDC Lib "gdi32" (ByVal hdc As Long) As Long Private Declare Function CreateCompatibleBitmap Lib "gdi32" (ByVal hdc As Long, ByVal nWidth As Long, ByVal nHeight As Long) As Long Private Declare Function SelectObject Lib "gdi32" (ByVal hdc As Long, ByVal hObject As Long) As Long Private Declare Function DeleteDC Lib "gdi32" (ByVal hdc As Long) As Long Private Declare Function GetWindowRect Lib "user32.dll" (ByVal hwnd As Long, ByRef lpRect As RECT) As Long Private Declare Function SetStretchBltMode Lib "gdi32.dll" (ByVal hdc As Long, ByVal nStretchMode As Long) As Long Private Declare Function StretchBlt Lib "gdi32.dll" (ByVal hdc As Long, ByVal x As Long, ByVal y As Long, ByVal nWidth As Long, ByVal nHeight As Long, ByVal hSrcDC As Long, ByVal xSrc As Long, ByVal ySrc As Long, ByVal nSrcWidth As Long, ByVal nSrcHeight As Long, ByVal dwRop As Long) As Long Private Declare Function DeleteObject Lib "gdi32.dll" (ByVal hObject As Long) As Long Function GetPictureControl(oControl As Object, Zoom As Integer) As Picture Dim hdc As Long Dim hDCMemory As Long, hBmp As Long, hBmpPrev As Long Dim hDCMemory2 As Long, hBmp2 As Long, hBmpPrev2 As Long Dim tRect As RECT Dim lWidth As Long, lHeight As Long Dim NewWidth As Long, NewHeight As Long Dim Pic As PicBmp, IPic As IPicture, IID_IDispatch As GUID GetWindowRect oControl.hwnd, tRect lWidth = tRect.Right - tRect.Left lHeight = tRect.Bottom - tRect.Top hdc = GetDC(0) hDCMemory = CreateCompatibleDC(0) hBmp = CreateCompatibleBitmap(hdc, lWidth, lHeight) hBmpPrev = SelectObject(hDCMemory, hBmp) PrintWindow oControl.hwnd, hDCMemory, 0 NewWidth = (lWidth * Zoom / 100) NewHeight = (lHeight * Zoom / 100) hDCMemory2 = CreateCompatibleDC(0) hBmp2 = CreateCompatibleBitmap(hdc, NewWidth, NewHeight) hBmpPrev2 = SelectObject(hDCMemory2, hBmp2) SetStretchBltMode hDCMemory2, vbPaletteModeNone StretchBlt hDCMemory2, 0, 0, NewWidth, NewHeight, hDCMemory, 0, 0, lWidth, lHeight, vbSrcCopy ReleaseDC 0, hdc DeleteObject SelectObject(hDCMemory, hBmpPrev) Call DeleteDC(hDCMemory) Call SelectObject(hDCMemory2, hBmpPrev2) Call DeleteDC(hDCMemory2) With IID_IDispatch .Data1 = &H20400 .Data4(0) = &HC0 .Data4(7) = &H46 End With With Pic .Size = Len(Pic) .Type = vbPicTypeBitmap .hBmp = hBmp2 End With Call OleCreatePictureIndirect(Pic, IID_IDispatch, 1, IPic) Set GetPictureControl = IPic End Function
y en el formulario lo llamas asi con un zoom de 150 (si lo queres tal cual le pones 100) Private Sub Command1_Click() Me.Picture = GetPictureControl(Picture1, 150) End Sub
Saludos.
Título: Re: Capturar contenido en un Picturebox
Publicado por: Brian1511 en 15 Enero 2015, 19:02 pm
Hola amigo muchas gracias por el code, me funciono a la perfeccion, ahora la duda que tengo es que me gustaria que se pudiece guardar no que se printee en el formulario! :), Es posible?
|