How can Small Basic access pictures under Q&A

Scout 136 Reputation points
2021-01-08T19:18:06.63+00:00

How can a Small Basic program to be published access images.
So far it was possible via the forum link (msdn) of the picture.
Can this also be carried out under Q&A (docs) or is the JPG file with 1.8MB not permitted?

'cow = Shapes.AddImage("/api/attachments/54924--igp0075-mini.jpg")?platform=QnA  
    
  cow = Shapes.AddImage("https://social.msdn.microsoft.com/Forums/getfile/1353849")  
Small BASIC
Small BASIC
A programming language created by Microsoft that serves a stepping stone for beginners from block-based coding languages to more complex text-based languages.
277 questions
{count} votes

7 answers

Sort by: Most helpful
  1. LitDev 126 Reputation points
    2023-09-11T22:10:42.3333333+00:00

    LDNetwork.SetSSL() in LitDev version 1.2.25.0 sorts some of this.
    See https://litdev.uk/mybb/showthread.php?tid=2

    2 people found this answer helpful.
    0 comments No comments

  2. Nonki Takahashi 676 Reputation points
    2021-01-20T08:55:44.62+00:00

    Hi @Scout , I guess Small Basic can't access SSL/TLS. If you have your own http site, that will be fine. If you are using Small Basic Desktop and LitDev Extension, LDNetwork.DownloadFile() may download some https files but your three images have still security problems. Thanks.

       url = "/api/attachments/54924--igp0075-mini.jpg"?platform=QnA  
       url = "/api/attachments/54954-wn54.gif"?platform=QnA  
       url = "/api/attachments/54955-crazyhorse.jpg"?platform=QnA  
       url = "https://social.msdn.microsoft.com/Forums/getfile/1353849"  
       path = Program.Directory + "\" + LDFile.GetFile(url) + "." + LDFile.GetExtension(url)  
       LDNetwork.DownloadFile(path, url)  
       GraphicsWindow.DrawImage(path, 10, 10)  
    
    1 person found this answer helpful.
    0 comments No comments

  3. Scout 541 Reputation points
    2021-02-21T10:41:25.21+00:00

    With the help of the LitDev extension and the LDImage.GetPixel () and .SetPixel () methods, image data can also be written in string arrays.
    The array can be saved as a SmallBasic file and thus integrated into SmallBasic programs.
    These images can thus also be made available for further use with the publish / import function.
    If the picture is saved directly in the SmallBasic program, the program code has to be subtracted from the 64kB limit.
    With 9 bytes per pixel, however, the image size is very limited with approx. 7000 pixels or approx. 80x80 pixels.

    Here is a small demo with the import ID PSD845

    70371-bigpic2.png

    1 person found this answer helpful.
    0 comments No comments

  4. Scout 541 Reputation points
    2021-01-21T15:07:45.81+00:00

    Update September 2023: Downloading images from Flickr and Q&A is working again

    Thanks to the latest extension LitDev V1.25 (Beta), the Flickr command/object is functional again.

    Now it is also possible to access Q&A attachments!!!

    LDUtilities.FixFlickr()
    LDNetwork.SetSSL()
    
    GraphicsWindow.Top = 20
    GraphicsWindow.Left= 20
    TextWindow.Top = 20
    TextWindow.Left=700
    
    ' MSDN getfile resource : access possible 
    Size = LDNetwork.DownloadFile(Program.Directory + "test","https://social.msdn.microsoft.com/Forums/getfile/1353849") 
    TextWindow.WriteLine("Size=" + Size) 
    Im1 = ImageList.LoadImage(Program.Directory + "test") 
    show()  
    
    ' Q & A (no access) Size1 = LDNetwork.DownloadFile(Program.Directory + "test1","https://learn-attachment.microsoft.com/api/attachments/69706-3-ellipse-map-v3-partialannotation.png?platform=QnA") 
    TextWindow.WriteLine("Size1=" + Size1) 
    Im1 = ImageList.LoadImage(Program.Directory + "test1") 
    show() 
    
    ' Q & A (no access) 
    Size4 = LDNetwork.DownloadFile(Program.Directory + "\test4.jpg","https://learn-attachment.microsoft.com/api/attachments/98756-no-flickr.png?platform=QnA")
    TextWindow.WriteLine("Size4=" + Size4) 
    Im1 = ImageList.LoadImage(Program.Directory + "test4") 
    show()  
    
    ' Flickr Random Picture 
    url = Flickr.GetPictureOfMoment() 
    TextWindow.WriteLine("Flickr-URL=" + url) 
    Size2 = LDNetwork.DownloadFile(Program.Directory + "test2", url) 
    TextWindow.WriteLine("Size2=" + Size2) 
    Im1 = ImageList.LoadImage(Program.Directory + "test2") 
    show()  
    
    ' Flickr Random Picture with Tags : unique Tag necessary 
    url = Flickr.GetRandomPicture("elves") 
    TextWindow.WriteLine("Flickr-URL=" + url) 
    Size3 = LDNetwork.DownloadFile(Program.Directory + "test3", url)
    TextWindow.WriteLine("Size3=" + Size3) 
    Im1 = ImageList.LoadImage(Program.Directory + "test3") 
    show()  
    
    ' MSDN getfile resources : million of images but 99% screenshots 
    For nxt = 1353901 to 1353910 Step 1
      Size5 = LDNetwork.DownloadFile(Program.Directory +   "test"+nxt,"https://social.msdn.microsoft.com/Forums/getfile/" + nxt)TextWindow.WriteLine("Size"+nxt+"=" + Size5)
     Im1 = ImageList.LoadImage(Program.Directory + "test"+nxt)
     show()   
    EndFor  
    
    Sub show
       GraphicsWindow.DrawImage(Im1,0,0)
       Program.Delay(700) 
    EndSub
    


    Update May 2021: The Small Basic Command "Flickr" no longer works !

    test4

    Thanks for the infos about SSL/TLS @Nonki Takahashi

    Here are some attempts to load image data with SmallBasic:

    ' MSDN getfile resource : access possible
    Size = LDNetwork.DownloadFile(Program.Directory + "test","https://social.msdn.microsoft.com/Forums/getfile/1353849")
    TextWindow.WriteLine("Size=" + Size)

    ' Q & A no access
    Size1 = LDNetwork.DownloadFile(Program.Directory + "test1","/api/attachments/54955-crazyhorse.jpg")
    TextWindow.WriteLine("Size1=" + Size1)

    ' Flickr Random Picture
    url = Flickr.GetPictureOfMoment()
    TextWindow.WriteLine("Flickr-URL=" + url)
    Size2 = LDNetwork.DownloadFile(Program.Directory + "test2", url)
    TextWindow.WriteLine("Size2=" + Size2)

    ' Flickr Random Picture with Tags : unique Tag necessary
    url = Flickr.GetRandomPicture("Pictogram")
    TextWindow.WriteLine("Flickr-URL=" + url)
    Size3 = LDNetwork.DownloadFile(Program.Directory + "test3", url)
    TextWindow.WriteLine("Size3=" + Size3)

    ' Q & A no access
    Size4 = LDNetwork.DownloadFile(Program.Directory + "test4", "/api/attachments/58517-marionette.png")
    TextWindow.WriteLine("Size4=" + Size4)

    ' MSDN getfile resources : million of images but 99% screenshots
    For nxt = 1353777 to 1353888 Step 1
    Size5 = LDNetwork.DownloadFile(Program.Directory + "test"+nxt,"https://social.msdn.microsoft.com/Forums/getfile/" + nxt)
    TextWindow.WriteLine("Size"+nxt+"=" + Size5)
    Im1 = ImageList.LoadImage(Program.Directory + "test"+nxt)
    GraphicsWindow.DrawImage(Im1,0,0)
    EndFor

    Alternatively, the objects can also be created with the integrated drawing tools:

    • SmallBasic ................................. Simple 2D
    • SmallBasic+litdev(LD) .......... Nice 2D + 3D

    As in the example of the current challenge: [challenge-of-the-month-january-2021.html][1]

    
    
    0 comments No comments

  5. Scout 541 Reputation points
    2021-02-18T18:19:57.097+00:00

    It begins in one hour !
    Unfortunately, SmallBasic cannot download the picture as a background. 69773-icon-confused.gif

    69706-3-ellipse-map-v3-partialannotation.png

    tmpFile = File.GetTemporaryFilePath()
    'imageURL = "https://mars.nasa.gov/system/downloadable_items/45663_E_dsn-madrid.jpg"
    imageURL = "https://mars.nasa.gov/imgs/mars2020/jezero-overview.jpg"
    LDNetwork.DownloadFile(tmpFile,imageURL)
    P = ImageList.LoadImage(tmpFile)
    'PF = Network.DownloadFile("https://mars.nasa.gov/system/downloadable_items/45532_3-Ellipse_Map_v3_PartialAnnotation.png")
    'PF = Network.GetWebPageContents("https://mars.nasa.gov/system/downloadable_items/45532_3-Ellipse_Map_v3_PartialAnnotation.png")
    'P = ImageList.LoadImage("https://mars.nasa.gov/system/downloadable_items/45663_E_dsn-madrid.jpg")
    'P = ImageList.LoadImage("https://mars.nasa.gov/system/downloadable_items/45468_LandingSitesContextMap_featPerseverance.jpg")
    'P = ImageList.LoadImage("https://mars.nasa.gov/system/downloadable_items/45532_3-Ellipse_Map_v3_PartialAnnotation.png")
    'P = ImageList.LoadImage("http://litdev.co.uk/game_images/rubic.png")
    Height = ImageList.GetHeightOfImage(P)
    TextWindow.WriteLine(" Imagelist: " + P)
    TextWindow.WriteLine(" Height: " + Height)
    GraphicsWindow.DrawImage(P,0,0)