png errors

Post

Posted
Rating:
#1 (In Topic #1441)
Regular
rj71 is in the usergroup ‘Regular’
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?


Code (gambas)

  1.    Try File.save("/home/rjr/test/1/channimg.png", HttpClient.Download("http://192.168.1.72/imgs/1/channimg.png"))
  2.     If Error Then
  3.      'image not on server
  4.      Message("cant find image")
  5.      Else
  6.         'show img
  7.      pc = Picture.FromString(File.Load("/home/rjr/test/1/channimg.png"))
  8.       PictureBox1.Picture = pc
  9.       Endif
  10.  
  11.  
Online now: No Back to the top

Post

Posted
Rating:
#2
Avatar
Regular
thatbruce is in the usergroup ‘Regular’
I cant see anything wrong there, but I would have done it:

Code (gambas)

  1.   Try File.save("/home/rjr/test/1/channimg.png", HttpClient.Download("http://192.168.1.72/imgs/1/channimg.png"))
  2.     'image not on server
  3.     Message("cant find image")
  4.    Return
  5.      
  6.   'show img
  7.   PictureBox1.Picture = Picture.Load["/home/rjr/test/1/channimg.png"]
  8.  
  9.  

Online now: No Back to the top

Post

Posted
Rating:
#3
Avatar
Guru
cogier is in the usergroup ‘Guru’
For some reason, I could not get thatbruce code to work

Code (gambas)

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

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

Code (gambas)

  1.  Try File.save("/tmp/test.png", HttpClient.Download("https://gambas.one/files/test.png"))
  2.   PictureBox1.Picture = Picture.FromString(File.Load("/tmp/test.png"))
Online now: No Back to the top

Post

Posted
Rating:
#4
Guru
BruceSteers is in the usergroup ‘Guru’

cogier said

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

Code (gambas)

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


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

Code (gambas)

  1.  
  2.   PictureBox1.Picture = Picture.Load("/home/rjr/test/1/channimg.png")
  3.  
Online now: No Back to the top

Post

Posted
Rating:
#5
Avatar
Regular
thatbruce is in the usergroup ‘Regular’

BruceSteers said


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

Code (gambas)

  1.  
  2.   PictureBox1.Picture = Picture.Load("/home/rjr/test/1/channimg.png")
  3.  

Mea culpa! Soooooorryy. :oops:

Online now: No Back to the top

Post

Posted
Rating:
#6
Regular
rj71 is in the usergroup ‘Regular’
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.
Online now: No Back to the top

Post

Posted
Rating:
#7
Avatar
Regular
thatbruce is in the usergroup ‘Regular’
Glad to hear it.
BTW (after a bit of actual testing this time  ;) ) the minimal code is, for example:

Code (gambas)

  1.   Dim thispng As Picture = Picture.FromString(HttpClient.Download("https://www.w3.org/Graphics/PNG/666.png"))
  2.   PictureBox1.Picture = thispng
  3.  
(I had to use a publicly available web png file)

b

Online now: No Back to the top

Post

Posted
Rating:
#8
Regular
rj71 is in the usergroup ‘Regular’

thatbruce said

Glad to hear it.
BTW (after a bit of actual testing this time  ;) ) the minimal code is, for example:

Code (gambas)

  1.   Dim thispng As Picture = Picture.FromString(HttpClient.Download("https://www.w3.org/Graphics/PNG/666.png"))
  2.   PictureBox1.Picture = thispng
  3.  
(I had to use a publicly available web png file)

b

Thanks Bruce!
Online now: No Back to the top
1 guest and 0 members have just viewed this.