This documentation is for the old version. Go to the latest Graphics Mill docs

Generating Frames

If you want to create your own movie you can fulfill it by generating frames. AVI Processor Add-on for Graphics Mill can assist you with this task and allow you to start making video from scratch. This article describes how to achieve this goal.

You can easily generate frames following the steps below:

  1. Create an AVI writer object and initialize it.

  2. Create empty bitmap.

  3. Modify the bitmap using means of Graphics Mill for .NET such as drawing, applying effects, etc.

  4. Create Aurigma.GraphicsMill.Codecs.AviFrame object and pass the bitmap into it.

  5. Pass the frame created on the step 4 to the AddFrame(IFrame) method of the writer object.

  6. Repeat steps 2-5 as many times as needed.

  7. Close the writer object.

Let's consider how to produce a movie. The movie shows the text colored with red, which appears from the left side of the bitmap and goes to the right. In the middle of the bitmap it passes though the water drop where it is recolored into blue. After the text has passed the water drop it becomes red back. The result video movie will be looking as follows:

Frame #0: Frame #0
Frame #25: Frame #25
Frame #50: Frame #50
Frame #75: Frame #75
Frame #100: Frame #100

The code snippet below shows how to do it.

Visual Basic
Public Shared Sub GenerateFrames(ByVal outputAviFilename As String)

    ' Text, its appearance settings, quantity of frames and radius of ripples
    ' in a water drop are specified here.    
    Dim text As String = "Sample text"
    Dim frameCount As Integer = 100
    Dim rippleRadius As Integer = 60
    Dim textColor As Aurigma.GraphicsMill.RgbColor = Aurigma.GraphicsMill.RgbColor.Red

    Dim font As New Aurigma.GraphicsMill.Drawing.Font("Arial", 40)
    font.Italic = True
    font.Underline = True

    Dim Brush As New Aurigma.GraphicsMill.Drawing.SolidBrush

    ' Create the writer object and initialize it.
    Dim writer As New Aurigma.GraphicsMill.Codecs.AviWriter
    writer.CompressorHandler = Aurigma.GraphicsMill.Codecs.AviCompressor.MSVideo1
    writer.FramesPerSecond = 24
    writer.Open(outputAviFilename)

    ' Here we measure width and height of the text. 
    ' These parameters are used when generating frames.
    Dim textSize As System.Drawing.SizeF = font.MeasureString(text)

    ' The code in this loop generates bitmaps and adds them to 
    ' the video.
    Dim I As Integer
    For I = 0 To frameCount

        ' for (int i=0; i<frameCount; i++)

        ' Create the empty bitmap. Dimensions of the bitmap depend on the size 
        ' of the text and the radius of the ripple.
        Dim bitmap As New Aurigma.GraphicsMill.Bitmap(Aurigma.GraphicsMill.RgbColor.White, _
          2 * (textSize.Width + rippleRadius + 1), _
          textSize.Height, _
          Aurigma.GraphicsMill.PixelFormat.Format24bppRgb)

        ' Draw the text to the bitmap. The X coordinate of the text is calculated so 
        ' that the text moves from left to right.
        Dim graphics As Aurigma.GraphicsMill.Drawing.GdiGraphics = bitmap.GetGdiGraphics()
        Brush.Color = textColor
        graphics.DrawString(text, _
          font, _
          Brush, _
          I * (textSize.Width + 2 * (rippleRadius + 1)) / frameCount, _
          0)

        ' Apply the water drop effect in the center of the bitmap.
        bitmap.Transforms.WaterDrop(bitmap.Width \ 2, _
         bitmap.Height \ 2, _
         rippleRadius, _
         20, _
         20)

        ' Get a grayscale mask from the bitmap. This mask is used 
        ' to recolor the area under the water drop into blue.

        Dim mask As Aurigma.GraphicsMill.Bitmap = bitmap.GetEmptyMask()
        graphics = mask.GetGdiGraphics()
        Brush.Color = Aurigma.GraphicsMill.RgbColor.White
        graphics.FillRectangle(Brush, _
          bitmap.Width \ 2 - rippleRadius, _
          bitmap.Height \ 2 - rippleRadius, _
          rippleRadius * 2, _
          rippleRadius * 2)

        ' Recolor the area under the water drop using the mask generated above.
        Dim hsl As New Aurigma.GraphicsMill.Transforms.AdjustHsl
        hsl.Hue = -0.6F
        hsl.ApplyMaskTransform(bitmap, mask)

        ' Add the result to the video file.
        writer.AddFrame(New Aurigma.GraphicsMill.Codecs.AviFrame(bitmap))

        ' Cleanup.
        bitmap.Dispose()
        mask.Dispose()
    Next

    ' Cleanup.
    writer.Close()
End Sub
C#
public static void GenerateFrames(string outputAviFilename)
{
    // Text, its appearance settings, quantity of frames and radius of ripples
    // in a water drop are specified here.    
    string text = "Sample text";
    int frameCount = 101;
    int rippleRadius = 60;
    Aurigma.GraphicsMill.RgbColor textColor = Aurigma.GraphicsMill.RgbColor.Red;

    Aurigma.GraphicsMill.Drawing.Font font = 
        new Aurigma.GraphicsMill.Drawing.Font("Arial", 40);
    font.Italic = true;
    font.Underline = true;

    Aurigma.GraphicsMill.Drawing.SolidBrush brush = 
        new Aurigma.GraphicsMill.Drawing.SolidBrush();

    // Create the writer object and initialize it.
    Aurigma.GraphicsMill.Codecs.AviWriter writer = 
        new Aurigma.GraphicsMill.Codecs.AviWriter();        
    writer.CompressorHandler = Aurigma.GraphicsMill.Codecs.AviCompressor.MSVideo1;
    writer.FramesPerSecond = 24;
    writer.Open(outputAviFilename);

    // Here we measure width and height of the text. 
    // These parameters are used when generating frames.
    System.Drawing.SizeF textSize = font.MeasureString(text);

    // The code in this loop generates bitmaps and adds them to 
    // the video.
    for (int i=0; i<frameCount; i++)
    {
        // Create the empty bitmap. Dimensions of the bitmap depend on the size 
        // of the text and the radius of the ripple.
        Aurigma.GraphicsMill.Bitmap bitmap = 
            new Aurigma.GraphicsMill.Bitmap(Aurigma.GraphicsMill.RgbColor.White, 
            2*((int)textSize.Width + rippleRadius + 1), 
            (int)textSize.Height, 
            Aurigma.GraphicsMill.PixelFormat.Format24bppRgb);
        
        // Draw the text to the bitmap. The X coordinate of the text is 
        // calculated so that the text moves from left to right.
        Aurigma.GraphicsMill.Drawing.GdiGraphics graphics = bitmap.GetGdiGraphics();                
        brush.Color = textColor;
        graphics.DrawString(text, 
            font, 
            brush, 
            i * (textSize.Width + 2*(rippleRadius + 1)) / frameCount, 
            0);
        
        // Apply the water drop effect in the center of the bitmap.
        bitmap.Transforms.WaterDrop(bitmap.Width/2, 
            bitmap.Height/2, rippleRadius, 20, 20);

        // Get a grayscale mask from the bitmap. This mask is used 
        // to recolor the area under the water drop into blue.
        Aurigma.GraphicsMill.Bitmap mask = bitmap.GetEmptyMask();
        graphics = mask.GetGdiGraphics();
        brush.Color = Aurigma.GraphicsMill.RgbColor.White;
        graphics.FillRectangle(brush, 
            bitmap.Width / 2 - rippleRadius, 
            bitmap.Height / 2 - rippleRadius, 
            rippleRadius * 2, 
            rippleRadius * 2);

        // Recolor the area under the water drop using the mask generated above.
        Aurigma.GraphicsMill.Transforms.AdjustHsl hsl = 
            new Aurigma.GraphicsMill.Transforms.AdjustHsl();
        hsl.Hue = -0.6f;
        hsl.ApplyMaskTransform(bitmap, mask);

        // Add the result to the video file.
        writer.AddFrame(new Aurigma.GraphicsMill.Codecs.AviFrame(bitmap));
        
        // Cleanup.
        bitmap.Dispose();
        mask.Dispose();
    }

    // Cleanup.
    writer.Close();
}

See Also

Manual