Page 1 of 1

Save WebGadget contents as image?

Posted: Thu Mar 17, 2005 11:51 pm
by PB
Is there a way to save whatever is displayed in the WebGadget as an image?

Posted: Fri Mar 18, 2005 1:08 am
by Max.
Not much I can say about it, but in case it might help;

I used such a program some time ago and it apparantly made a screenshot of the window, then automatically scrolled to a new position, made screenshot again and so on until it had the entire content and finally puzzled the pieces together.

Maybe now it's possible to get a complete screenshot using the render engine, but the above way seems to be relatively easy to implement. Relatively.

Edit:

Is it possible to use the print mechanism, using a printer driver that creates an image?

Re: Save WebGadget contents as image?

Posted: Fri Mar 18, 2005 2:05 am
by ricardo
PB wrote:Is there a way to save whatever is displayed in the WebGadget as an image?
Only a screenshot of the webgadget.

Posted: Fri Mar 18, 2005 2:15 am
by dagcrack
That would not be useful.

Posted: Fri Mar 18, 2005 9:29 am
by Kale
After some tests i can't seem to get a screenshot of the webgadget, it always displays blank. Strange! :?

Posted: Fri Mar 18, 2005 11:41 am
by Fred
You could try to send it the famous WM_PRINT message with a 2DDrawing DC as argument.

Posted: Fri Mar 18, 2005 11:45 am
by Edwin Knoppert
O well, i did this a while ago.
Does not work that smoothly but maybe you want to see it.
It's on my site in the free downloads 'Website to Pic'
It's an exe though.

Posted: Fri Mar 18, 2005 6:26 pm
by ricardo
Once i do it in VB with no problem.
I was designing a website and need to get the thumbs of each site listed on my website (1,500)... i develope a small VB that does the job for me in one night... just taking screenshoots.

Posted: Fri Mar 18, 2005 6:44 pm
by ricardo
Fast code, not the best, but give you an idea and get the picture of the webgadget

Code: Select all


UseJPEGImageEncoder() 
Global xX, yY
xX = GetSystemMetrics_(#SM_CXSCREEN) : yY = GetSystemMetrics_(#SM_CYSCREEN)
Procedure.l CaptureScreen(Left.l, Top.l, Width.l, Height.l) 
    dm.DEVMODE 
    BMPHandle.l 
    srcDC = CreateDC_("DISPLAY", "", "", dm) 
    trgDC = CreateCompatibleDC_(srcDC) 
    BMPHandle = CreateCompatibleBitmap_(srcDC, Width, Height) 
    SelectObject_( trgDC, BMPHandle) 
    BitBlt_( trgDC, 0, 0, Width, Height, srcDC, Left, Top, #SRCCOPY) 
    DeleteDC_( trgDC) 
    ReleaseDC_( BMPHandle, srcDC) 
    ProcedureReturn BMPHandle 
EndProcedure 

Procedure CreaImagen()
    DeleteFile("Screenshot.jpeg")
    ScreenCaptureAddress = CaptureScreen(20,40,xX-50,yY-150)
    CreateImage(0, xX, yY) 
    StartDrawing(ImageOutput()) 
    DrawImage(ScreenCaptureAddress, 0, 0) 
    StopDrawing() 
    SaveImage(0, "Screenshot.jpeg",#PB_ImagePlugin_JPEG,10)
    Beep_(1999,100)
    ProcedureReturn 1
EndProcedure

If OpenWindow(0,0,0,xX,yY,#PB_Window_SystemMenu,"Test")
    CreateGadgetList(WindowID())
    ButtonGadget(2,(xX/2),yY-90,150,25,"Take Picture")
    WebGadget(3,10,10,xX-50,yY-150,"http://www.google.com")
    Repeat
        EventID=WaitWindowEvent()
        Select EventID
            
            Case #PB_EventGadget
                Select EventGadgetID()
                    Case 2
                      CreaImagen()  
                EndSelect
                
        EndSelect
        
    Until EventID=#PB_EventCloseWindow
EndIf



Posted: Fri Mar 18, 2005 11:01 pm
by PB
Thanks to all who replied! :)

Posted: Sun Mar 20, 2005 3:47 am
by Sparkie
I'm working on a app that converts a web page into a JPG/PNG/BMP image. You can choose to take a snapshot of the viewable area of the web page, or take a snapshot of the entire page, even though it's not in view. 8)
Converts this to this.
This is a stage 1 prototype for a possible commercial app I'm woking on. I can't release the source, but if it's for your personal use, and you're interested, I'll see if I can make a lib for you to use. :)

Posted: Mon Jan 19, 2009 11:39 am
by Michael Vogel
Hi,
found this good ol' thread when searching for a possibility to get a google map into an image...

I have two problems now:
- I am able to get a picture which conatins only the upper 100 of the web content, the rest stays white
- if I try to do the whole process hidden (adding the #PB_Window_Invisible flag) , the image stays completely black (okay that's for phase 2 :wink: )

I have already inserted even a longer delay before saving the picture, but the result have been exactly the same...

Can anyone give me a hint, what I'm doing wrong here?

Thanks,
Michael

Code: Select all

Procedure SavePicture()
	UsePNGImageEncoder() 
	DeleteFile("c:\Screenshot.png")
	windowhandle=WindowID(0)
	GetClientRect_(windowhandle, @cr.RECT)
	CreateImage(0, cr\right-cr\left, cr\bottom-cr\top, 24)
	hdc=StartDrawing(ImageOutput(0))
	SendMessage_(windowhandle, #WM_PRINT, hdc, #PRF_CLIENT|#PRF_CHILDREN|#PRF_ERASEBKGND|#PRF_CHECKVISIBLE )
	StopDrawing()
	Debug SaveImage(0, "c:\Screenshot.png",#PB_ImagePlugin_PNG)
EndProcedure


If OpenWindow(0,0,0,800,500,"X",#PB_Window_SizeGadget | #PB_Window_SystemMenu | #PB_Window_MinimizeGadget |#PB_Window_MaximizeGadget | #PB_Window_ScreenCentered)
	WebGadget(1, 0, 0, 800, 500, "http://www.purebasic.com",#PB_Web_Mozilla )

	saveflag=0

	Repeat
		Event = WaitWindowEvent(100)
		
		If saveflag=1
			Debug "wait..."
			If GetGadgetAttribute(1,#PB_Web_Busy)=0
				Delay(10)
				Debug "Save now!"
				saveflag=2
				Repeat
					WindowEvent()
				Until WaitWindowEvent(0)=0
				SavePicture()
			EndIf
		EndIf


		Select Event

		Case #PB_Event_Gadget
			Select EventGadget()
			Case 1
				Select EventType()
				Case #PB_Event_DataReceived
					;Debug "Data"
				Case  #PB_EventType_DownloadEnd
					If saveflag=0
						saveflag=1
					EndIf
					;Debug "Download"
				Case #PB_EventType_StatusChange
					;Debug "Changes"
				EndSelect
			EndSelect
		EndSelect
	Until Event=#PB_Event_CloseWindow


EndIf

Posted: Mon Jan 19, 2009 9:06 pm
by waldschrath
The following works for me:

Code: Select all

Procedure SavePicture()
	UsePNGImageEncoder() 
	DeleteFile("c:\Screenshot.png")
	windowhandle=GadgetID(1)
	GetClientRect_(windowhandle, @cr.RECT)
	CreateImage(0, cr\right-cr\left, cr\bottom-cr\top, 24)
	hdc=StartDrawing(ImageOutput(0))
	SendMessage_(windowhandle, #WM_PRINT, hdc, #PRF_CLIENT|#PRF_CHILDREN|#PRF_ERASEBKGND)
	StopDrawing()
	Debug SaveImage(0, "c:\Screenshot.png",#PB_ImagePlugin_PNG)
EndProcedure

Posted: Mon Jan 19, 2009 11:46 pm
by Kiffi
perhaps this could be useful too:

http://www.purebasic.fr/english/viewtop ... 652#268652

Greetings ... Kiffi

Posted: Tue Jan 20, 2009 2:00 pm
by Michael Vogel
Thanks to all, especially to waldschrath (oh, you found my idiotic error!)

No it works perfect 8)

Michael