elhacker.net cabecera Bienvenido(a), Visitante. Por favor Ingresar o Registrarse
¿Perdiste tu email de activación?.

 

 


Tema destacado: Estamos en la red social de Mastodon


+  Foro de elhacker.net
|-+  Programación
| |-+  Programación General
| | |-+  .NET (C#, VB.NET, ASP)
| | | |-+  Programación Visual Basic (Moderadores: LeandroA, seba123neo)
| | | | |-+  Capturar contenido en un Picturebox
0 Usuarios y 1 Visitante están viendo este tema.
Páginas: [1] Ir Abajo Respuesta Imprimir
Autor Tema: Capturar contenido en un Picturebox  (Leído 2,383 veces)
Brian1511

Desconectado Desconectado

Mensajes: 268


¿Quien soy esa es la gran pregunta?


Ver Perfil WWW
Capturar contenido en un Picturebox
« 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:




Quisiera hacer una captura a todo lo que este en su interior, pero en forma de imagen ;)

Gracias de antemano!
Un saludo!


En línea



Creador de BrainMind
LeandroA
Moderador
***
Desconectado Desconectado

Mensajes: 760


www.leandroascierto.com


Ver Perfil WWW
Re: Capturar contenido en un Picturebox
« Respuesta #1 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
Código
  1. Option Explicit
  2.  
  3. Private Type GUID
  4.    Data1 As Long
  5.    Data2 As Integer
  6.    Data3 As Integer
  7.    Data4(7) As Byte
  8. End Type
  9.  
  10. Private Type PicBmp
  11.    Size As Long
  12.    Type As Long
  13.    hBmp As Long
  14.    hPal As Long
  15.    Reserved As Long
  16. End Type
  17.  
  18. Private Type RECT
  19.    Left As Long
  20.    Top As Long
  21.    Right As Long
  22.    Bottom As Long
  23. End Type
  24.  
  25. Private Declare Function GetDC Lib "user32.dll" (ByVal hwnd As Long) As Long
  26. Private Declare Function ReleaseDC Lib "user32.dll" (ByVal hwnd As Long, ByVal hdc As Long) As Long
  27. Private Declare Function PrintWindow Lib "user32.dll" (ByVal hwnd As Long, ByVal hdcBlt As Long, ByVal nFlags As Long) As Long
  28. Private Declare Function OleCreatePictureIndirect Lib "olepro32.dll" (PicDesc As PicBmp, RefIID As GUID, ByVal fPictureOwnsHandle As Long, IPic As IPicture) As Long
  29. Private Declare Function CreateCompatibleDC Lib "gdi32" (ByVal hdc As Long) As Long
  30. Private Declare Function CreateCompatibleBitmap Lib "gdi32" (ByVal hdc As Long, ByVal nWidth As Long, ByVal nHeight As Long) As Long
  31. Private Declare Function SelectObject Lib "gdi32" (ByVal hdc As Long, ByVal hObject As Long) As Long
  32. Private Declare Function DeleteDC Lib "gdi32" (ByVal hdc As Long) As Long
  33. Private Declare Function GetWindowRect Lib "user32.dll" (ByVal hwnd As Long, ByRef lpRect As RECT) As Long
  34. Private Declare Function SetStretchBltMode Lib "gdi32.dll" (ByVal hdc As Long, ByVal nStretchMode As Long) As Long
  35. 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
  36. Private Declare Function DeleteObject Lib "gdi32.dll" (ByVal hObject As Long) As Long
  37.  
  38.  
  39. Function GetPictureControl(oControl As Object, Zoom As Integer) As Picture
  40.    Dim hdc As Long
  41.    Dim hDCMemory As Long, hBmp As Long, hBmpPrev As Long
  42.    Dim hDCMemory2 As Long, hBmp2 As Long, hBmpPrev2 As Long
  43.    Dim tRect As RECT
  44.    Dim lWidth As Long, lHeight As Long
  45.    Dim NewWidth As Long, NewHeight As Long
  46.    Dim Pic As PicBmp, IPic As IPicture, IID_IDispatch As GUID
  47.  
  48.    GetWindowRect oControl.hwnd, tRect
  49.  
  50.    lWidth = tRect.Right - tRect.Left
  51.    lHeight = tRect.Bottom - tRect.Top
  52.  
  53.    hdc = GetDC(0)
  54.    hDCMemory = CreateCompatibleDC(0)
  55.    hBmp = CreateCompatibleBitmap(hdc, lWidth, lHeight)
  56.    hBmpPrev = SelectObject(hDCMemory, hBmp)
  57.  
  58.    PrintWindow oControl.hwnd, hDCMemory, 0
  59.  
  60.  
  61.    NewWidth = (lWidth * Zoom / 100)
  62.    NewHeight = (lHeight * Zoom / 100)
  63.  
  64.    hDCMemory2 = CreateCompatibleDC(0)
  65.    hBmp2 = CreateCompatibleBitmap(hdc, NewWidth, NewHeight)
  66.    hBmpPrev2 = SelectObject(hDCMemory2, hBmp2)
  67.  
  68.    SetStretchBltMode hDCMemory2, vbPaletteModeNone
  69.    StretchBlt hDCMemory2, 0, 0, NewWidth, NewHeight, hDCMemory, 0, 0, lWidth, lHeight, vbSrcCopy
  70.  
  71.    ReleaseDC 0, hdc
  72.  
  73.    DeleteObject SelectObject(hDCMemory, hBmpPrev)
  74.    Call DeleteDC(hDCMemory)
  75.  
  76.    Call SelectObject(hDCMemory2, hBmpPrev2)
  77.    Call DeleteDC(hDCMemory2)
  78.  
  79.    With IID_IDispatch
  80.        .Data1 = &H20400
  81.        .Data4(0) = &HC0
  82.        .Data4(7) = &H46
  83.    End With
  84.  
  85.  
  86.    With Pic
  87.        .Size = Len(Pic)
  88.        .Type = vbPicTypeBitmap
  89.        .hBmp = hBmp2
  90.    End With
  91.  
  92.    Call OleCreatePictureIndirect(Pic, IID_IDispatch, 1, IPic)
  93.  
  94.    Set GetPictureControl = IPic
  95.  
  96.  
  97. End Function
  98.  

y en el formulario lo llamas asi con un zoom de 150 (si lo queres tal cual le pones 100)
Código
  1. Private Sub Command1_Click()
  2.    Me.Picture = GetPictureControl(Picture1, 150)
  3. End Sub
  4.  


Saludos.


En línea

Brian1511

Desconectado Desconectado

Mensajes: 268


¿Quien soy esa es la gran pregunta?


Ver Perfil WWW
Re: Capturar contenido en un Picturebox
« Respuesta #2 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?
En línea



Creador de BrainMind
Páginas: [1] Ir Arriba Respuesta Imprimir 

Ir a:  

WAP2 - Aviso Legal - Powered by SMF 1.1.21 | SMF © 2006-2008, Simple Machines