Marblecore Imaging Library Documentation

Documentation Introduction
Documentation / Marblecore Imaging / Methods / SaveToStream

SaveToStream method

Saves the current image (in the specified format) and returns the stream. The stream data contains all binary information which is normally saved to a physic file when you save the image to a file using the SaveToFile method. You can use the stream to save the image to a file using your own custom function. You can also use the stream to transfer image objects within your application, so you don't have to save the image to (temporary) files. If you just want to transfer image data from one image object to another image object, use the Serialize, Deserialize and LoadFromSerializedStream functions. Those methods give better performance for internal image data transfers.

Syntax

Stream SaveToStream(nFormat As Format, nBPP As Number, nLeft As Number, nTop As Number, nWidth As Number, nHeight As Number)

Return value

Returns a stream with the binairy data.

Parameters

ParameterTypeRequiredDescription
nFormatFormat (Enumeration)NoOptional parameter containing the format for the file.
nBPPNumberNoOptional parameter containing the number of bits per pixel for the file.
nLeftNumberNoOptional parameter which specifies the left coordinate of the rectangle to return.
nTopNumberNoOptional parameter which specifies the top coordinate of the rectangle to return.
nWidthNumberNoOptional parameter which specifies the width of the rectangle to return.
nHeightNumberNoOptional parameter which specifies the height of the rectangle to return.

Example

The SaveToStream method can be used to save an image and stream it to a webserver. The example below shows how to use this method in classic ASP to create an image and stream it to the browser using VBScript. In this example we also disabled the ASP session support using the ENABLESESSIONSTATE directive. This gives better performance for returning images through ASP.
 
1 <%@ Language=VBScript @ENABLESESSIONSTATE=FALSE %>
2 <%
3 
4 Dim MyImage
5 
6 ' Create a new image object
7 Set MyImage = CreateObject("Marblecore.Imaging")
8 
9 ' Create a new image of 200x200 pixels
10 MyImage.Create 200, 200
11 
12 ' Draw a red filled rectangle on it
13 MyImage.DrawRectangleFilled 0, 0, 200, 200, MyImage.GetColorFromHTML("#ff0000")
14 
15 ' Set the content type and write the image to the response stream
16 Response.ContentType = MyImage.GetMIMEFromFormat("PNG")
17 Response.BinaryWrite MyImage.SaveToStream("PNG")
18 
19 %>

Category

Basic operations

See also

Create | Deserialize | LoadFromBase64 | LoadFromFile | LoadFromSerializedStream | LoadFromStream | LoadFromURL | Reset | SaveToBase64 | SaveToFile | SaveToHBitmap | SaveToHBitmapPreMultiplied | Serialize | Working with streams