Alex Fenton
2009-Feb-13 07:02 UTC
[wxruby-users] téléchargement et affichage d'image avec HtmlWindow
Hi sebastien wrote:> Je ne trouve pas la m?thode qui pourrait me permettre de t?l?charger > des images sur le web sans avoir ce genre de message d''erreur quand je > les affiches avec "HtmlWindow": > Corrupt JPEG data: 1 extraneous bytes before marker 0xdb > Quelles m?thodes peut-on utilis??[Sebastien asked: I haven''t found a way of downloading an image from the web without having this sort of message when I display it with HtmlWindow: "Corrupt JPEG data: 1 extraneous byte before marker 0xdb". What method should I use.] C''est difficile de t''aider sans avoir vu le code que t''utilise pour t?l?charger et afficher l''image. Un conjecture: quand tu t?l?charges le fichier, tu l''enregistres avec File.open: File.open("image.jpg", "w") { | file | file.write(http_body) } Sur Windows, si on ?crit un fichier binaire, on doit mettre ''b'' dans le deuxi?me argument ? File.open: File.open("image.jpg", "wb") { | file | file.write(http_body) } [It''s difficult to help without having seen the code which you''re using to download and display the image. At a guess, when you download the file, because it''s a binary, you need to add ''b'' to the second argument to File.open when you write it to the disk]. alex
Bonsoir Alex, voici la m?thode que j''utilisait en attente de trouv? la solution: lecture = open(mon_url).read open("img.jpg", "w") {|f| f << lecture} je ne savais pas qu''il fallait mettre le ''b'' dans le deuxi?me argument pour ?crire un fichier binaire: File.open("image.jpg", "wb") { | file | file.write(http_body) } j''ai essayer le code ci-dessus et ?a marche. Je te remercie. S?bastien beusse.liveror.com -------------- section suivante -------------- Une pi?ce jointe HTML a ?t? nettoy?e... URL: <rubyforge.org/pipermail/wxruby-users/attachments/20090213/fb0b4240/attachment.html>