From lispercat at gmail.com Wed May 30 14:42:40 2007 From: lispercat at gmail.com (Andrei Stebakov) Date: Wed, 30 May 2007 10:42:40 -0400 Subject: [cl-gd-devel] Image to array of bytes Message-ID: Instead of saving an image into a file using write-image-to-file I was trying to provide a hunchentoot handler which outputs an array of bytes (just like in the hunchentoot test.lisp image-ram-page example). For this I thought write-jpeg-to-stream would be the best candidate so I did following: (let ((s (make-string-output-stream :element-type '(unsigned-byte 8)))) (write-jpeg-to-stream s :image bg-image) (let ((image-data (make-array (image-size bg-image) :element-type '(unsigned-byte 8)))) (read-sequence image-data s) image-data))))))) For which the SBCL complains: # is not a binary output stream. I am wondering if I am doing the right thing and choosing the right function for the task. I also tried to create a stream with flexi-stream:make-in-memory-output-stream without any success. Thank you, Andrew ** -------------- next part -------------- An HTML attachment was scrubbed... URL: From edi at agharta.de Wed May 30 15:10:40 2007 From: edi at agharta.de (Edi Weitz) Date: Wed, 30 May 2007 17:10:40 +0200 Subject: [cl-gd-devel] Image to array of bytes In-Reply-To: (Andrei Stebakov's message of "Wed, 30 May 2007 10:42:40 -0400") References: Message-ID: On Wed, 30 May 2007 10:42:40 -0400, "Andrei Stebakov" wrote: > Instead of saving an image into a file using write-image-to-file I > was trying to provide a hunchentoot handler which outputs an array > of bytes (just like in the hunchentoot test.lisp image-ram-page > example). For this I thought write-jpeg-to-stream would be the best > candidate so I did following: > > (let ((s (make-string-output-stream :element-type '(unsigned-byte 8)))) > (write-jpeg-to-stream s :image bg-image) > (let ((image-data (make-array (image-size bg-image) :element-type > '(unsigned-byte 8)))) > (read-sequence image-data s) > image-data))))))) > > For which the SBCL complains: > # is not a binary output stream. > > I am wondering if I am doing the right thing and choosing the right > function for the task. I also tried to create a stream with > flexi-stream:make-in-memory-output-stream without any success. MAKE-STRING-OUTPUT-STREAM can't work because it's a /string/ stream, as the name says. The FLEXI-STREAMS approach should work, though. If it doesn't, show us your code. I wonder why you're doing all this, though. Why don't you write directly to the Hunchentoot stream? (You know about SEND-HEADERS, don't you?) Cheers, Edi. From lispercat at gmail.com Wed May 30 16:55:24 2007 From: lispercat at gmail.com (Andrei Stebakov) Date: Wed, 30 May 2007 12:55:24 -0400 Subject: [cl-gd-devel] Image to array of bytes In-Reply-To: References: Message-ID: Thanks, Edi. I didn't know about send-headers. Now everything works. On 5/30/07, Edi Weitz wrote: > > On Wed, 30 May 2007 10:42:40 -0400, "Andrei Stebakov" > wrote: > > > Instead of saving an image into a file using write-image-to-file I > > was trying to provide a hunchentoot handler which outputs an array > > of bytes (just like in the hunchentoot test.lisp image-ram-page > > example). For this I thought write-jpeg-to-stream would be the best > > candidate so I did following: > > > > (let ((s (make-string-output-stream :element-type '(unsigned-byte > 8)))) > > (write-jpeg-to-stream s :image bg-image) > > (let ((image-data (make-array (image-size bg-image) > :element-type > > '(unsigned-byte 8)))) > > (read-sequence image-data s) > > image-data))))))) > > > > For which the SBCL complains: > > # is not a binary output > stream. > > > > I am wondering if I am doing the right thing and choosing the right > > function for the task. I also tried to create a stream with > > flexi-stream:make-in-memory-output-stream without any success. > > MAKE-STRING-OUTPUT-STREAM can't work because it's a /string/ stream, > as the name says. The FLEXI-STREAMS approach should work, though. If > it doesn't, show us your code. > > I wonder why you're doing all this, though. Why don't you write > directly to the Hunchentoot stream? (You know about SEND-HEADERS, > don't you?) > > Cheers, > Edi. > _______________________________________________ > cl-gd-devel site list > cl-gd-devel at common-lisp.net > http://common-lisp.net/mailman/listinfo/cl-gd-devel > -------------- next part -------------- An HTML attachment was scrubbed... URL: