Notifications
Clear all

[Closed] Image Stream from web

I’ve tried to play a little with displaying an image in my form, from web, without downloading it to hard drive.

here is how I download the file:

(
		local webClient = dotnetObject "System.Net.WebClient"	
		url = "http://shopmd.ml/parse/example/imagine.jpg"
		theUri=dotnetObject "System.Uri" url
		--newFile = ((getDir #temp) + "//" + ((dotnetclass "System.IO.Path").getfilename theUri.LocalPath))
		newFile = ("D:\\" + ((dotnetclass "System.IO.Path").getfilename theUri.LocalPath))
		webClient.DownloadFileAsync theUri newFile
		ok
)		

Here is a function how to read a webpage

(
 	webdata = ""
  	fn Completed sender arg =
 	(
 		sender.Dispose();
 		print webdata
 	)	
 	fn getWebData sender arg =
 	(
 		wrGETURL = (dotnetclass "System.Net.WebRequest").Create(arg.Argument);
 		wrGETURL.proxy = (dotnetclass "System.Net.WebProxy").GetDefaultProxy();
 		response = wrGETURL.GetResponse();
 		objstream = response.GetResponseStream()
 		objReader = dotnetobject "System.IO.StreamReader" objStream;
 		sline = "";
 		while sline != undefined do
 		(
 			sLine = objReader.ReadLine();
 			if sLine != undefined then
 				webdata += sline;
 		)	
 	)
 
 	fn GetThePage ip = 
 	(	
 		local thread = dotnetobject "System.ComponentModel.BackGroundWorker"
 		dotnet.addeventhandler thread "DoWork" getWebData;
 		dotNet.addeventhandler thread "RunWorkerCompleted" Completed;
 		thread.RunWorkerAsync ip;
 		thread.IsBusy
 	)
 		
 	(	
 		GetThePage "http://shopmd.ml/parse/example/imagine.jpg"
 
 	)
 )

Here is a function by Lonel Robot:

		fn base64str_to_dotnet_image str = --  http://lonerobot.net/ 
		(
			ConvertClass = dotNetClass "System.Convert"
			ImageClass = dotNetClass "System.Drawing.Image"
			byteArr = ConvertClass.FromBase64String str
			memstream = dotnetobject "System.IO.MemoryStream" byteArr
			DecodedImg = ImageClass.fromstream memstream
			memstream.close() ; 
			DecodedImg --return
		)--end fn

Is it possible to convert this image data in a such a way that I could apply it to a form?

I mean

mybtn.image = base64str_to_dotnet_image webdata

6 Replies
frm = dotnetobject "system.windows.forms.form"
btn = dotnetobject "system.windows.forms.button"
frm.controls.add btn

frm.autosizemode = frm.autosizemode.GrowAndShrink
frm.autosize = true
btn.autosize = true

url = @"http://www.relatably.com/m/img/depressed-frog-memes/E5AA3B5AC91160120055967674368_34fb7f79dad.1.4.jpg"

fn getImageFromWeb url = (
	
	request = (dotnetclass "system.net.WebRequest").Create url

	response = request.GetResponse()
	stream = response.GetResponseStream()

    (dotnetclass "System.Drawing.Bitmap").FromStream stream
	
)

btn.image = getImageFromWeb url

frm.show()

maybe you can skip entire base64 part?

Thank you, Serejah, it reads usual images but unfortunatelly it does not read captcha.

can you provide any link to that captcha?
i suggest using copy to clipboard for that, but need to check

yes: “

very strange, in the morning it was not working, now it does.

1 Reply
(@momo2012)
Joined: 11 months ago

Posts: 0

With years experience,I think WebRequest sometimes cause this problem, that’s why most of time this code works,but sometimes,WebRequest can not get data from a url,so of cause can not work.
Cause this issue may it’s the DNS problem I think,I am not sure,maybe this morning it works due to this reason.


request = (dotnetclass "system.net.WebRequest").Create url