Hi again,

2006/7/14, Jason Johnston <[EMAIL PROTECTED]>:
Christian Sengstock wrote:
> Hello list,
>
> in my application i generate dynamically a BufferedImage object and i
> want to complete the pipeline with sending the image as a "mime-type:
> image/jpeg" response.
>
> At the moment i have a matcher which takes the request and calls a
> flowScript function which in turn handles the dynamic creation of the
> BufferedImage. Afterwards i save the image to disk and send the URI of
> the image-file via the cocoon.sendPage( <filename.jpeg> ) function to
> the sitemap, where a reader handles the proper response as a mime-type
> image/jpeg.
>
> This is working for me but i thought that there might be a better
> approach to do this. Maybe without saving the BufferedImage to disk.
>
> Can anybody give me a hint how to create a "mime-type: image" response
> out of a BufferedImage? Maybe it's possible by extending a reader or
> by using a serializer?


If you can get the content of your BufferedImage as an InputStream or
byte[] array (sorry I don't know that API), then you can pass it along
as view data in sendPage(), and serve it up with the standard
ResourceReader and the ModuleSource:


=== flowscript: ===

var imageInputStream = ...
cocoon.sendPage("image-pipeline", {imageInputStream:imageInputStream});


==== sitemap: ===

<map:match pattern="image-pipeline">
   <map:read src="module:flow-attr:imageInputStream"
             mime-type="image/jpeg" />
</map:match>


--Jason

---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]



thanx a lot, that solved my problem!
this is how i did it (in fact like you told it) ...

### my java class #
/** method to create an inputStream out of a bufferedImage */
public InputStream getInputStream (String dynamicImagePara) {
  // getting a bufferedImage dynamically
  BufferedImage image = createImage (dynamicImagePara);

  // converting to inputStream - found in the web
  ByteArrayOutputStream baos = new  ByteArrayOutputStream();
  ImageIO.write(image, "jpeg", baos);
  InputStream is = new ByteArrayInputStream(baos.toByteArray());

  return is
}

### FlowScript #
var inputStream =  aboveObject.getInputStream ( parameter );
cocoon.sendPage("wms-pipe", { "inputStream" : inputStream });

### SiteMap #
<map:match pattern="wms-pipe">
 <map:read src="module:flow-attr:inputStream" mime-type="image/jpeg" />
</map:match>


thanx,
chris

---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to