Save WebGadget contents as image?

Just starting out? Need help? Post your questions and find answers here.
PB
PureBasic Expert
PureBasic Expert
Posts: 7581
Joined: Fri Apr 25, 2003 5:24 pm

Save WebGadget contents as image?

Post by PB »

Is there a way to save whatever is displayed in the WebGadget as an image?
I compile using 5.31 (x86) on Win 7 Ultimate (64-bit).
"PureBasic won't be object oriented, period" - Fred.
Max.
Enthusiast
Enthusiast
Posts: 225
Joined: Fri Apr 25, 2003 8:39 pm

Post 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?
Athlon64 3800+ · 1 GB RAM · Radeon X800 XL · Win XP Prof/SP1+IE6.0/Firefox · PB 3.94/4.0
Intel Centrino 1.4 MHz · 1.5 GB RAM · Radeon 9000 Mobility · Win XP Prof/SP2+IE6.0/Firefox · PB 3.94/4.0
ricardo
Addict
Addict
Posts: 2438
Joined: Fri Apr 25, 2003 7:06 pm
Location: Argentina

Re: Save WebGadget contents as image?

Post 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.
ARGENTINA WORLD CHAMPION
dagcrack
Addict
Addict
Posts: 1868
Joined: Sun Mar 07, 2004 8:47 am
Location: Argentina
Contact:

Post by dagcrack »

That would not be useful.
Kale
PureBasic Expert
PureBasic Expert
Posts: 3000
Joined: Fri Apr 25, 2003 6:03 pm
Location: Lincoln, UK
Contact:

Post by Kale »

After some tests i can't seem to get a screenshot of the webgadget, it always displays blank. Strange! :?
--Kale

Image
Fred
Administrator
Administrator
Posts: 18204
Joined: Fri May 17, 2002 4:39 pm
Location: France
Contact:

Post by Fred »

You could try to send it the famous WM_PRINT message with a 2DDrawing DC as argument.
Edwin Knoppert
Addict
Addict
Posts: 1073
Joined: Fri Apr 25, 2003 11:13 pm
Location: Netherlands
Contact:

Post 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.
ricardo
Addict
Addict
Posts: 2438
Joined: Fri Apr 25, 2003 7:06 pm
Location: Argentina

Post 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.
ARGENTINA WORLD CHAMPION
ricardo
Addict
Addict
Posts: 2438
Joined: Fri Apr 25, 2003 7:06 pm
Location: Argentina

Post 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


ARGENTINA WORLD CHAMPION
PB
PureBasic Expert
PureBasic Expert
Posts: 7581
Joined: Fri Apr 25, 2003 5:24 pm

Post by PB »

Thanks to all who replied! :)
I compile using 5.31 (x86) on Win 7 Ultimate (64-bit).
"PureBasic won't be object oriented, period" - Fred.
Sparkie
PureBatMan Forever
PureBatMan Forever
Posts: 2307
Joined: Tue Feb 10, 2004 3:07 am
Location: Ohio, USA

Post 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. :)
What goes around comes around.

PB 5.21 LTS (x86) - Windows 8.1
User avatar
Michael Vogel
Addict
Addict
Posts: 2806
Joined: Thu Feb 09, 2006 11:27 pm
Contact:

Post 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
waldschrath
New User
New User
Posts: 8
Joined: Fri Nov 03, 2006 8:58 am

Post 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
User avatar
Kiffi
Addict
Addict
Posts: 1499
Joined: Tue Mar 02, 2004 1:20 pm
Location: Amphibios 9

Post by Kiffi »

perhaps this could be useful too:

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

Greetings ... Kiffi
Hygge
User avatar
Michael Vogel
Addict
Addict
Posts: 2806
Joined: Thu Feb 09, 2006 11:27 pm
Contact:

Post by Michael Vogel »

Thanks to all, especially to waldschrath (oh, you found my idiotic error!)

No it works perfect 8)

Michael
Post Reply