# tÃ©lÃ©chargement et affichage d 'image avec HtmlWindow

**URL:** <https://www.ruby-forum.com/t/ta-la-chargement-et-affichage-d-image-avec-htmlwindow/160229>\
**Category:** wxRuby\
**Created:** [February 13, 2009, 7:41am UTC](https://www.ruby-forum.com/t/ta-la-chargement-et-affichage-d-image-avec-htmlwindow/160229 "2009-02-13T07:41:45Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![beusse](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/b/439d5e/32.png) [@beusse](https://www.ruby-forum.com/u/beusse)\
**Post date:** [February 13, 2009, 7:41am UTC](https://www.ruby-forum.com/t/ta-la-chargement-et-affichage-d-image-avec-htmlwindow/160229/1 "2009-02-13T07:41:45Z")

</div>

Bonjour Ã tous.  
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Ã©?  
Je vous remercie.  
SÃ©bastien  
[http://beusse.liveror.com/](http://beusse.liveror.com/)

---

<div class="post-metadata">

**Author:** ![beusse](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/b/439d5e/32.png) [@beusse](https://www.ruby-forum.com/u/beusse)\
**Post date:** [February 13, 2009, 8:15am UTC](https://www.ruby-forum.com/t/ta-la-chargement-et-affichage-d-image-avec-htmlwindow/160229/2 "2009-02-13T08:15:05Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![beusse](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/b/439d5e/32.png) [@beusse](https://www.ruby-forum.com/u/beusse)\
**Post date:** [February 13, 2009, 6:28pm UTC](https://www.ruby-forum.com/t/ta-la-chargement-et-affichage-d-image-avec-htmlwindow/160229/3 "2009-02-13T18:28:49Z")

</div>

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  
[http://beusse.liveror.com/](http://beusse.liveror.com/)
