png errors

Post your Gambas programming questions here.
Post Reply
rj71
Regular
Posts: 131
Joined: Thu Apr 13, 2023 6:39 pm
Location: Vancouver WA

png errors

Post by rj71 »

Hi All,

I have an unusual error and wondering if anyone can help. In the simple test code below I am downloading a specific .png file from my web server. The file downloads but will not open. Error says it's not a png file. There is nothing wrong with the png on the server, I can download through webmin and open it just fine. I use this code a lot downloading jpgs and never had a problem. The download path on the server is correct, I have been staring at it for hours so it is right. Is there something about downloading and saving a png that I am missing? Should I do something different for png files?


 Dim pc As Picture
   Try File.save("/home/rjr/test/1/channimg.png", HttpClient.Download("http://192.168.1.72/imgs/1/channimg.png")) 
    If Error Then
     'image not on server
     Message("cant find image")
     Else 
        'show img
     pc = Picture.FromString(File.Load("/home/rjr/test/1/channimg.png"))
      PictureBox1.Picture = pc
      Endif 

User avatar
thatbruce
Regular
Posts: 293
Joined: Sat Sep 04, 2021 11:29 pm

Re: png errors

Post by thatbruce »

I cant see anything wrong there, but I would have done it:
Dim pc As Picture
  Try File.save("/home/rjr/test/1/channimg.png", HttpClient.Download("http://192.168.1.72/imgs/1/channimg.png")) 
   If Error Then
    'image not on server
    Message("cant find image")
   Return
  Endif
      
  'show img
  PictureBox1.Picture = Picture.Load["/home/rjr/test/1/channimg.png"]

User avatar
cogier
Site Admin
Posts: 1197
Joined: Wed Sep 21, 2016 2:22 pm
Location: Guernsey, Channel Islands

Re: png errors

Post by cogier »

For some reason, I could not get thatbruce code to work

'show img
  PictureBox1.Picture = Picture.Load["/home/rjr/test/1/channimg.png"]


This works, you can test it as the file exists online.

 Try File.save("/tmp/test.png", HttpClient.Download("https://gambas.one/files/test.png"))
  PictureBox1.Picture = Picture.FromString(File.Load("/tmp/test.png"))
BruceSteers
Legend
Posts: 2093
Joined: Thu Jul 23, 2020 5:20 pm
Location: Isle of Wight

Re: png errors

Post by BruceSteers »

cogier wrote: Thu Mar 20, 2025 9:58 am For some reason, I could not get thatbruce code to work

'show img
  PictureBox1.Picture = Picture.Load["/home/rjr/test/1/channimg.png"]

it's because he used [angle brackets] not (parenthesis) by mistake.
Picture.Load() is of course a method


  PictureBox1.Picture = Picture.Load("/home/rjr/test/1/channimg.png")
User avatar
thatbruce
Regular
Posts: 293
Joined: Sat Sep 04, 2021 11:29 pm

Re: png errors

Post by thatbruce »

BruceSteers wrote: Thu Mar 20, 2025 10:18 am
it's because he used [angle brackets] not (parenthesis) by mistake.
Picture.Load() is of course a method


  PictureBox1.Picture = Picture.Load("/home/rjr/test/1/channimg.png")
Mea culpa! Soooooorryy. :oops:
rj71
Regular
Posts: 131
Joined: Thu Apr 13, 2023 6:39 pm
Location: Vancouver WA

Re: png errors

Post by rj71 »

Thanks guys. I solved it. Really embarrassing but it was an ownership problem that i didn't notice. :oops: I could have swore I checked it but I guess I didn't.
User avatar
thatbruce
Regular
Posts: 293
Joined: Sat Sep 04, 2021 11:29 pm

Re: png errors

Post by thatbruce »

Glad to hear it.
BTW (after a bit of actual testing this time ;) ) the minimal code is, for example:
  Dim thispng As Picture = Picture.FromString(HttpClient.Download("https://www.w3.org/Graphics/PNG/666.png"))
  PictureBox1.Picture = thispng
(I had to use a publicly available web png file)

b
rj71
Regular
Posts: 131
Joined: Thu Apr 13, 2023 6:39 pm
Location: Vancouver WA

Re: png errors

Post by rj71 »

thatbruce wrote: Thu Mar 20, 2025 2:10 pm Glad to hear it.
BTW (after a bit of actual testing this time ;) ) the minimal code is, for example:
  Dim thispng As Picture = Picture.FromString(HttpClient.Download("https://www.w3.org/Graphics/PNG/666.png"))
  PictureBox1.Picture = thispng
(I had to use a publicly available web png file)

b
Thanks Bruce!
Post Reply