---
title: "Working with Streams"
canonical: https://www.graphicsmill.com/docs/gm5/WorkingwithStreams.htm
product: "Graphics Mill 5.5 for .NET"
---

This documentation is for the old version. [Go to the latest Graphics Mill docs](https://www.graphicsmill.com/docs/gm/)

# Working with Streams
 
Streams provides universal way to exchange large blocks of data. It enables you to abstract your mind from physical organization of data source or sink. Therefore you can operate with data stored at files, database, Internet, etc.
 
.NET Framework provides a number of classes derived from abstract class System.IO.Stream. This class provides all methods necessary to get or put data from or into the stream. You can pass a stream [Load](https://www.graphicsmill.com/docs/gm5/O_T_Aurigma_GraphicsMill_Bitmap_Load.htm.md) and [Save](https://www.graphicsmill.com/docs/gm5/O_T_Aurigma_GraphicsMill_Bitmap_Save.htm.md) methods of the [Bitmap](https://www.graphicsmill.com/docs/gm5/T_Aurigma_GraphicsMill_Bitmap.htm.md) class, as well as open appropriate format reader or writer on stream.
 
At this topic we will demonstrate how to send an image from server to client browser. Also you can read about such application of streams as [working with database](https://www.graphicsmill.com/docs/gm5/LoadingandSavingImagestoDatabase.htm.md), as well as [loading a file from given URL](https://www.graphicsmill.com/docs/gm5/WorkingwithURL.htm.md).
 
To send any data from server to client ASP.NET provides special intrinsic object called **Response**. It has a property **OutputStream**. When you write into this stream, data is sent to client. So we should just use this property as input parameter for Save methods of the Bitmap class.
 
The code example below demonstrates that. Copy this code into separate file and call it, for example, **WorkWithStreams1.aspx**.
 
```
Private Sub Page_Load(ByVal sender As System.Object, ByVal e As System.EventArgs)
    Dim bitmap As New Bitmap(Server.MapPath("SourceImages/Mountain.jpg"))
    
    'Resize to 100 pixels width
    bitmap.Transforms.Resize(100, 0, InterpolationMode.MediumQuality)

    'Save image to response stream
    Response.Clear()    
    bitmap.Save(Response.OutputStream, New JpegEncoderOptions(70, true))
    Response.End()
End Sub
```
 
```csharp
private void Page_Load(object sender, System.EventArgs e)
{
    Bitmap bitmap = new Bitmap(Server.MapPath(@"SourceImages/Mountain.jpg"));
    
    //Resize to 100 pixels width
    bitmap.Transforms.Resize(100, 0, InterpolationMode.MediumQuality);

    //Save image to response stream
    Response.Clear();
    bitmap.Save(Response.OutputStream, new JpegEncoderOptions(70, true));
    Response.End();
}
```
 
Quite often you should display not only one image, but also some additional HTML. But if you write any binary data into output stream of the **Response**, the client browser will not be able to handle HTML code sent into the same stream.
 
To avoid this and display additional HTML around the image we create, we need to make some additional tricks. Create a separate page which contain all necessary HTML code. At the position you need to display the image add tag **&lt;img&gt;** and set **src** attribute with an URL to the page which sends an image to client (i.e. **WorkWithStreams1.aspx** in our case).
 
Here is an example of this code:
 
```aspx-cs
<html><body bgcolor="#DDDDDD">	<img src="WorkWithStreams1.aspx"></body>
</html>
```
