---
title: "Working with EPS"
canonical: https://www.graphicsmill.com/docs/gm/working-with-eps.htm
product: "Graphics Mill"
---

# Working with EPS
 
Encapsulated PostScript (EPS) is a PostScript document that is used as a graphics file format. An EPS file may contain both raster and vector data described with the PostScript language.
 
Graphics Mill provides two ways to create EPS documents: using the [Bitmap](https://www.graphicsmill.com/docs/gm/T_Aurigma_GraphicsMill_Bitmap.htm.md) and [EpsWriter](https://www.graphicsmill.com/docs/gm/T_Aurigma_GraphicsMill_Codecs_EpsWriter.htm.md) classes. Graphics Mill does not provide a full EPS processor, but it can read TIFF previews if any. To read a TIFF preview, you can use the [EpsReader](https://www.graphicsmill.com/docs/gm/T_Aurigma_GraphicsMill_Codecs_EpsReader.htm.md) class. This topic describes these EPS features.
 
## Using Bitmaps
  
Using a **Bitmap** is the simplest way to create EPS documents. All you need to do is create a **Bitmap**, draw graphics on it, and save it as an EPS using the [Bitmap.Save](https://www.graphicsmill.com/docs/gm/O_T_Aurigma_GraphicsMill_Bitmap_Save.htm.md) method. The following snippet illustrates how to do this:
 
```csharp
using (var bitmap = new Bitmap(200, 80, PixelFormat.Format24bppRgb, RgbColor.White))
using (var graphics = bitmap.GetGraphics())
{
    var plainText = new PlainText("Plain Text", graphics.CreateFont("Arial", 28), new System.Drawing.PointF(20, 40));
    graphics.DrawText(plainText);
    bitmap.Save(@"Images\Output\out.eps", new EpsSettings(CompressionType.Jpeg, 90));
}
```
 
Notice that **Bitmap.Save** allows you to choose an algorithm for the bitmap compression and its quality.
 
## Using EpsWriter
  
**EpsWriter** is the more flexible way to create EPS documents. Using this class, you can create an EPS containing raster images and vector shapes. You can also draw vector text, which has advantages over raster - it scales without diminishing quality. All drawing on the EPS is performed via [Graphics](https://www.graphicsmill.com/docs/gm/T_Aurigma_GraphicsMill_Drawing_Graphics.htm.md), which is returned by the [EpsWriter.GetGraphics()](https://www.graphicsmill.com/docs/gm/M_Aurigma_GraphicsMill_Codecs_EpsWriter_GetGraphics.htm.md) method. To learn how to draw on **Graphics** in detail, read the [Drawing](https://www.graphicsmill.com/docs/gm/advanced-drawing.htm.md) section. Here is the snippet demonstrating how to create **EpsWriter** with the specified size and DPI, and then get the **Graphics** from it that are necessary for drawing:
 
```csharp
var dpi = 300f;
using (var epsWriter = new EpsWriter(@"Images\Output\out.eps", 500, 500, dpi, dpi))
using (var graphics = epsWriter.GetGraphics())
{
    //...
}
```
 
**EpsWriter** does not allow for specifying a color space or color profile for the resulting document. Each graphic element drawn on the EPS has its own color space, and it may contain a color profile. This allows for drawing graphic elements with different pixel formats on the same document. For instance, if you draw an RGB bitmap with an sRGB color profile and delineate it with a CMYK rectangle, both of these elements will be displayed correctly according to their color spaces and the image will be stored with an embedded sRGB color profile:
 
```csharp
using (var epsWriter = new EpsWriter(@"Images\Output\out.eps", 210, 160))
using (var graphics = epsWriter.GetGraphics())
{
    //Draw the RGB bitmap with an sRGB color profile.
    using (var bitmap = new Bitmap(@"Images\RgbImage.jpg"))
    {
        //Assign a standard sRGB profile.
        bitmap.ColorProfile = ColorProfile.FromSrgb();
        graphics.DrawImage(bitmap, 10, 10);
    }
    //Draw the CMYK rectangle.
    graphics.DrawRectangle(new Pen(new CmykColor(43, 65, 92, 44), 4), 9, 9, 190, 141);
}
```
 
Here is the result of this snippet:
 ![Generating Eps](https://www.graphicsmill.com/docs/gm/WorkingWithEPS1.png) 
When creating the EPS, you may need to work with device independent coordinates (for example, inches) instead of pixels. However, all constructors of **EpsWriter** will only accept the EPS size in pixels. In this case, you can use the [UnitConverter.ConvertUnitsToPixels(Single, Single, Unit)](https://www.graphicsmill.com/docs/gm/M_Aurigma_GraphicsMill_UnitConverter_ConvertUnitsToPixels_3_1df1b0a2.htm.md) method that converts inches to pixels according to the given DPI. Assume that we need to create 3.5"x2.5" EPS with 300 DPI. Here is the snippet showing how to do this:
 
```csharp
var epsDPI = 300f;
using (var epsWriter = new EpsWriter(@"Images\out.eps", UnitConverter.ConvertUnitsToPixels(dpi, 3.5f, Unit.Inch),
        UnitConverter.ConvertUnitsToPixels(dpi, 2.0f, Unit.Inch), epsDPI, epsDPI))
using (var graphics = epsWriter.GetGraphics())
{
    //...
}
```
 
An image drawn on an EPS document may have an alpha channel specifying an opacity degree for each pixel. However, the EPS format cannot handle semi-transparency, that is, each pixel in EPS images can only be displayed with full opacity or full transparency. **EpsWriter** allows you to specify a threshold for transparency via the [AlphaThreshold](https://www.graphicsmill.com/docs/gm/P_Aurigma_GraphicsMill_Codecs_EpsWriter_AlphaThreshold.htm.md) property. **AlphaThreshold** values are accepted in the range `[0, 1]`. If a pixel's alpha value is greater than the **AlphaThreshold**, the pixel will be fully opaque; otherwise, it will be fully transparent. Let us assume that we have a picture with a transparent frame produced by the snippet below:
 
```csharp
using (var bitmap = new Bitmap(200, 151, PixelFormat.Format32bppArgb, new RgbColor(255, 255, 255, 20)))
using (var graphics = bitmap.GetGraphics())
{
    graphics.DrawImage(new Bitmap(@"Images\RgbImage.jpg"), new System.Drawing.RectangleF(8, 8, 184, 136));
    //Draw a rectangle with transparency.
    var pen = new Pen(new RgbColor(0, 88, 0, 150), 8);
    graphics.DrawRectangle(pen, 4, 4, 192, 143);

    bitmap.Save(@"Images\Output\out.png");
}
```
 ![Bitmap With Transparency](https://www.graphicsmill.com/docs/gm/WorkingWithEPS2.png) 
Now we need to draw this image on the EPS. If we specify the **AlphaThreshold** property at `0.7`, which is greater than the frame transparency, then the frame will be invisible as the following image illustrates:
 ![EPS Invisible Frame](https://www.graphicsmill.com/docs/gm/WorkingWithEPS3.png) 
This image was produced by the snippet below:
 
```csharp
using (var epsWriter = new EpsWriter(@"Images\Output\out.eps", 200, 151))
{
    epsWriter.AlphaThreshold = 0.7f;
    using (var graphics = epsWriter.GetGraphics())
        graphics.DrawImage(new Bitmap(@"Images\Output\out.png"), new System.Drawing.RectangleF(0, 0, 200, 151));
}
```
 
If we specify **AlphaThreshold** at `0.5`, which is smaller than the frame transparency, then the frame will be opaque:
 ![EPS AlphaThreshold](https://www.graphicsmill.com/docs/gm/WorkingWithEPS4.png)
 
## Reading TIFF Preview
  
Graphics Mill allows you to read TIFF previews from EPS files. The following example shows how you can read a TIFF preview and save it into a PNG file using memory-friendly Pipeline API.
 
```csharp
using (var reader = new EpsReader(@"Images\seal.eps"))
using (var writer = new PngWriter(@"Images\Output\out.png"))
{
    Pipeline.Run(reader + writer);
}
```
 
## See Also
  
### Reference
 
- [Bitmap Class](https://www.graphicsmill.com/docs/gm/T_Aurigma_GraphicsMill_Bitmap.htm.md)
- [EpsWriter Class](https://www.graphicsmill.com/docs/gm/T_Aurigma_GraphicsMill_Codecs_EpsWriter.htm.md)
- [UnitConverter Class](https://www.graphicsmill.com/docs/gm/T_Aurigma_GraphicsMill_UnitConverter.htm.md)
- [UnitConverter.ConvertUnitsToPixels(Single, Single, Unit) Method](https://www.graphicsmill.com/docs/gm/M_Aurigma_GraphicsMill_UnitConverter_ConvertUnitsToPixels_3_1df1b0a2.htm.md)
- [Pipeline Class](https://www.graphicsmill.com/docs/gm/T_Aurigma_GraphicsMill_Pipeline.htm.md)

### Manual
 
- [Working with Files](https://www.graphicsmill.com/docs/gm/working-with-files.htm.md)
- [Drawing](https://www.graphicsmill.com/docs/gm/advanced-drawing.htm.md)
