We would like to build a community for Small Basic programmers of any age who like to code. Everyone from total beginner to guru is welcome. Click here to register and share your programming journey!


Thread Rating:
  • 2 Vote(s) - 5 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Small Basic Only Extension
#21
LitDev,

I did see that imagelist.downloadfile went into a temp file. I was thinking there has to be something that we're not seeing. Thanks for checking on things that have me stumped. It's good to have someone to work with that is a whole lot smarter than me.

JR
Reply
#22
OK, I understand the issue I think.

SmallBasicLibrary uses Network.DownloadFile for all network file access, including within ImageList.LoadImage.

The code for DownloadFile includes this to read the data:

Code:
long num = webResponse.ContentLength;
stream2 = webResponse.GetResponseStream();
while (num > 0)
{
int num2 = stream2.Read(buffer, 0, 16384);
stream.Write(buffer, 0, num2);
num -= num2;
}

This fails for Flickr image urls as we know, using Network.DownloadFile or ImageList.LoadImage.

The code I use in LDBasic.DownloadFile is slightly different (apart from the SSL stuff):

Code:
                Stream stream = webResponse.GetResponseStream();
                int readCount = stream.Read(buffer, 0, bufferSize);
                while (readCount > 0)
                {
                    fs.Write(buffer, 0, readCount);
                    readCount = stream.Read(buffer, 0, bufferSize);
                }

So SmallBasicLibrary tests webResponse.ContentLength to check size.  Google 'webResponse.ContentLength' if interested.

The documentation for it states:

Quote:The ContentLength property contains the value of the Content-Length header returned with the response. If the Content-Length header is not set in the response, ContentLength is set to the value -1.

So, this is an 'optional' setting included in the web response header (not set by Flikr, probably changed at some point).  Standard SmalBasicLibrary cannot work for web urls that don't have this property set.
[-] The following 1 user Likes litdev's post:
  • z-s
Reply
#23
LitDev,

Bear with me I am trying to understand this. In the original code "long num = webResponse.ContentLength" it is wanting num to be > 0. That isn't set in the webResponse. In your code you are setting readcount from the stream.read. and that value is greater than 0. Is my thinking right?

So, in conclusion we are better off not using network.download or imagelist.loadimage because it will sometimes not work. Best to use ldbasic.downloadfile() and ldbasic.loadimage() which should always work.

Good sleuthing!

JR
Reply
#24
Yes, thats about it I'm afraid.
Reply
#25
LitDev,

I did start a thread on the Small Basic forum mentioning the new extension. I mentioned what it does and what it's for and how to get it. So, we'll see how that goes.

By the way in this forum is there a way to send pictures? I wanted to do that the other day and couldn't figure out how to do it.

Same issue with code samples. Although with it I could just publish it and give whoever the id. Thanks for the help. I will continue through the tutorials looking for broke things.

JR
[-] The following 1 user Likes jrmrhrb00's post:
  • litdev
Reply
#26
For code samples you can put the code between (code)...(/code) with the ( ) replaced with [ ]
See the help https://litdev.uk/mybb/misc.php?action=help&hid=7

Code:
TextWindow.WriteLine("")
TextWindow.WriteLine("Various output")
TextWindow.WriteLine("")
[-] The following 1 user Likes WhTurner's post:
  • litdev
Reply
#27
LitDev,

I did find that Desktop.SetWallPaper doesn't work the way that it should even using the LDBasic commands. Here is a snippet of the code:

LDBasic.FixFlickr()
For image = 1 to 5
pic = Flickr.GetRandomPicture("landscape")
'wall=LDBasic.LoadImage(pic)
LDBasic.DownloadFile("c:\temp\test.jpg",pic)
'TextWindow.WriteLine(wall)
Desktop.SetWallPaper("c:\temp\test.jpg")
Program.Delay(10000)
EndFor

If I use LDBasic.LoadImage it doesn't change the wallpaper at all. Using download file it will change it one time. This code came from the "Small Basic Curriculum for the desktop object. I really don't understand why LDBasic.LoadImage doesn't work. Your thoughts? Is there something we need to add?

Here is the original program from the tutorial:

LDBasic.FixFlickr()
For image = 1 to 5
pic = Flickr.GetRandomPicture("landscape")
Desktop.SetWallPaper(pic)
Program.Delay(10000)
EndFor

I did get the multiple images to work with this: The LDBasic.LoadImage still mystifies me as to why it doesn't.

LDBasic.FixFlickr()
For image = 1 to 5
pic = Flickr.GetRandomPicture("landscape")
'TextWindow.WriteLine(pic)
Temp="c:\temp\test"+image+".jpg"
ldbasic.DownloadFile(Temp,pic)
'wall=ldbasic.LoadImage(pic)
'File.DeleteFile(temp)
TextWindow.WriteLine(temp)
Desktop.SetWallPaper(temp)
File.DeleteFile(temp)
Program.Delay(10000)
EndFor

JR
[-] The following 1 user Likes jrmrhrb00's post:
  • litdev
Reply
#28
As usual there is more than 1 thing going on:

1] Desktop.SetWallPaper needs a file (local or networded).  It does not work using an imagelist reference (for me this just sets the wallper to black). GW works as expected.

Code:
LDBasic.FixFlickr()
For image = 1 To 5
 
    pic = Flickr.GetRandomPicture("landscape")
    TextWindow.WriteLine(pic)
    wall = LDBasic.LoadImage(pic)
    TextWindow.WriteLine(wall)
    GraphicsWindow.DrawResizedImage(wall, 0,0,GraphicsWindow.Width,GraphicsWindow.Height)
    Desktop.SetWallPaper(wall)
 
  Program.Delay(1000)
EndFor

2] If the input file name is the same, it doesn't reload it, so the following works due to file name change

Code:
LDBasic.FixFlickr()
For image = 1 To 5
 
    pic = Flickr.GetRandomPicture("landscape")
    TextWindow.WriteLine(pic)
    fileName = "c:\temp\test"+image+".jpg"
    LDBasic.DownloadFile(fileName,pic)
    GraphicsWindow.DrawResizedImage(fileName, 0,0,GraphicsWindow.Width,GraphicsWindow.Height)
    Desktop.SetWallPaper(fileName)
 
  Program.Delay(1000)
EndFor

PS, I just saw you also spotted the file name issue!
Reply
#29
LitDev,

This is a program that was made by you a long time ago. Since it is the season I updated it to work again. You do have to have extension LDBasic loaded for it to run.

Import MLDS345.000

Merry Christmas!

JR
[-] The following 1 user Likes jrmrhrb00's post:
  • litdev
Reply


Forum Jump:


Users browsing this thread: 5 Guest(s)