Marblecore Imaging Library Documentation

Documentation Introduction

Working with streams

You can use Marblecore to load and save image files directly from (and to) disk. You can even use the LoadFromURL method to load an image directly from an URL (which is very convienent as much of the content nowadays resides online). But often you want to keep your images in memory. For example if you use the library within a defined process or when you want to stream an image back to a client (like through a webserver to a browser). Therefore the library contains stream functionality so you can load images from streams and save images back to streams.

Besides normal streams the library also contains a special internal stream format called serialized streams. These serialized streams are used for a different purpose: Transferring images between (or within) Marblecore Imaging objects. You can use these serialized streams when you want to insert (a part of) an image into another image or when working with different layers where each layer is represented by a Marblecore image object. The main difference is a big speed advantage. Normal streams are a exact representation of the contents of a formatted image file (like a JPEG, PNG or GIF file). When you load an image from a normal stream, the image is opened and decoded to a Marblecore image object for further processing. When you save an image back to a stream, the library encodes the image object to a stream with the desired image format. This encoding and decoding is overhead and unnecessary when you just want to transfer bitmap data (read image pixels). This page explains when to use normal streams and when to use the serialized stream solution.

Using normal streams

Use normal streams to load images from memory or to save images in the desired format back to a stream. The image stream in memory can be written directly to a file to create a physic copy of the image. All normal stream methods are suffixed with 'Stream' (instead of 'SerializedStream'). Below is an example how to use the SaveToStream method to deliver a PNG image through a webserver (using classic ASP and VBScript):
2 <%
4 Dim Image
6 ' Create a new image object
7 Set Image = Server.CreateObject("Marblecore.Imaging")
9 ' Create a new image of 200x200 pixels
10 Image.Create 200, 200
12 ' Draw a red filled rectangle on it
13 Image.DrawRectangleFilled 0, 0, 200, 200, Image.GetColorFromHTML("#ff0000")
15 ' Set the content type and write the image to the response stream
16 Response.ContentType = Image.GetMIMEFromFormat("PNG")
17 Response.BinaryWrite Image.SaveToStream("PNG")
19 %>
The following methods are available for working with normal streams:
LoadFromStream | SaveToStream | InsertFromStream | SaveHistogramToStream | LoadHistogramFromStream | FilterTextureFromStream | MaskOverlayFromStream

Using serialized streams

Use serialized streams if you want to transfer images between or within Marblecore image objects. It is a very fast method for transferring image pixels and gives much better perfomance than using normal streams. Use the serialized methods only for transferring data between or within Marblecore image objects. All serialized stream methods are suffixed with 'SerializedStream'. Below is an example how to create two separate images and blend them together using the Serialize and InsertFromSerializedStream methods:
1 // Create the first image and draw a red rectangle on it
2 Imaging1.Create(200, 200);
3 Imaging1.DrawRectangleFilled(0, 0, 200, 200, Imaging1.GetColorFromHTML("#ff0000"));
5 // Create the second image and draw a blue circle on it
6 Imaging2.Create(100, 100);
7 Imaging2.DrawEllipseFilled(0, 0, 100, 100, Imaging2.GetColorFromHTML("#0000ff"));
9 // Insert the second image into the first image with 75% opacity
10 Imaging1.InsertFromSerializedStream(Imaging2.Serialize(), 50, 50, 75);
The following methods are available for working with serialized streams:
Serialize | Deserialize | LoadFromSerializedStream | InsertFromSerializedStream | SaveHistogramToSerializedStream | LoadHistogramFromSerializedStream | FilterTextureFromSerializedStream | MaskOverlayFromSerializedStream