Hola a todos :D, estaba haciendo una aplicacion en donde capturo la pantalla de lo que se muestra en un webbrowser despues de hacer un resize, el problema es el siguiente:
Al momento de hacer la captura de pantalla, la nueva imagen se almacena en memoria y al hacer click en el boton "Vista Previa" la aplicacion se cae ya que aparece un mensaje diciendo que la propiedad "PictureBox1.Image es null".
(Lo cual me dice que la imagen capturada no se almacena en la propiedad Image del PictureBox).
Estaba intentando implementar eso y me dijeron que debia hacer previamente un "Save" en el Image del pictureBox para que la aplicacion no se caiga.
Mi aplicacion es la siguiente:
El Codigo del boton "Capturar" es este:
El Codigo posible y que nose bien como implementarlo (ya que no funciona) para guardar la imagen en la propiedad Image, es este:
Espero me puedan ayudar, gracias! ;D
Cita de: oscarj24 en 22 Junio 2010, 19:30 PM
El Codigo del boton "Capturar" es este:
El Codigo posible y que nose bien como implementarlo (ya que no funciona) para guardar la imagen en la propiedad Image, es este:
Es como una prueba donde hay que completar? :laugh:
Podrias
guardarlo en el disco y cargarlo en el picturebox (pa' codelive) o en un memoryStream ._.
jajaja no amigo, se envio de casualidad, el codigo de capturar es este:
Private Declare Function BitBlt Lib "gdi32" (ByVal hDestDC As Integer, ByVal X As Integer, ByVal Y As Integer, ByVal nWidth As Integer, ByVal nHeight As Integer, ByVal hSrcDC As Integer, ByVal xSrc As Integer, ByVal ySrc As Integer, ByVal dwRop As Integer) As Integer
Public Enum TernaryRasterOperations 'API BitBlt
SRCCOPY = &HCC0020
SRCPAINT = &HEE0086
SRCAND = &H8800C6
SRCINVERT = &H660046
SRCERASE = &H440328
NOTSRCCOPY = &H330008
NOTSRCERASE = &H1100A6
MERGECOPY = &HC000CA
MERGEPAINT = &HBB0226
PATCOPY = &HF00021
PATPAINT = &HFB0A09
PATINVERT = &H5A0049
DSTINVERT = &H550009
BLACKNESS = &H42
WHITENESS = &HFF0062
End Enum
Private Sub Capturar(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnCapturar.Click
Dim srcGraphics As Graphics = WebBrowser1.CreateGraphics
Try
Dim destGraphics As Graphics = PictureBox1.CreateGraphics
Try
Dim hdcDest As IntPtr = destGraphics.GetHdc
Dim hdcSrc As IntPtr = srcGraphics.GetHdc
BitBlt(hdcDest, 0, 0, WebBrowser1.ClientRectangle.Width, WebBrowser1.ClientRectangle.Height, hdcSrc, 0, 0, CType(TernaryRasterOperations.SRCCOPY, Integer))
srcGraphics.ReleaseHdc(hdcSrc)
destGraphics.ReleaseHdc(hdcDest)
lblCaptura.Visible = True
Finally
CType(destGraphics, IDisposable).Dispose()
End Try
Finally
CType(srcGraphics, IDisposable).Dispose()
End Try
End Sub
Mi aplicacion:
(http://img694.imageshack.us/img694/1022/appt.jpg)
El codigo posible a la solucion en el boton capturar pero que no me funciona:
Private Sub Capturar(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnCapturar.Click
Dim srcGraphics As Graphics = WebBrowser1.CreateGraphics
Try
Dim destGraphics As Graphics = PictureBox1.CreateGraphics
Dim bmpSource As New Bitmap(PictureBox1.Width, PictureBox1.Height, destGraphics)
bmpSource.Save("Image.jpg", System.Drawing.Imaging.ImageFormat.Jpeg)
Try
Dim hdcDest As IntPtr = destGraphics.GetHdc
Dim hdcSrc As IntPtr = srcGraphics.GetHdc
BitBlt(hdcDest, 0, 0, WebBrowser1.ClientRectangle.Width, WebBrowser1.ClientRectangle.Height, hdcSrc, 0, 0, CType(TernaryRasterOperations.SRCCOPY, Integer))
srcGraphics.ReleaseHdc(hdcSrc)
destGraphics.ReleaseHdc(hdcDest)
lblCaptura.Visible = True
PictureBox1.Image = bmpSource.Clone()
Finally
CType(destGraphics, IDisposable).Dispose()
End Try
Finally
CType(srcGraphics, IDisposable).Dispose()
End Try
End Sub
PD. Lo que no deseo hacer es guardarlo en el disco ya que esta ventanita es parte de un sistema en linea :D