BmpTransforms.cs
//
// This code is part of GrapeCity Documents for Imaging samples.
// Copyright (c) GrapeCity, Inc. All rights reserved.
//
using System;
using System.IO;
using System.Drawing;
using System.Collections.Generic;
using System.Linq;
using GrapeCity.Documents.Drawing;
using GrapeCity.Documents.Text;
using GrapeCity.Documents.Imaging;

namespace GcImagingWeb.Samples
{
    // This sample demonstrates how to use bitmap transformations
    // such as resizing, flipping and rotating.
    public class Transforms
    {
        public GcBitmap GenerateImage(int pixelWidth = 1024, int pixelHeight = 1024, bool opaque = true, float dpiX = 96, float dpiY = 96)
        {
            var bmp = new GcBitmap(pixelWidth, pixelHeight, opaque, dpiX, dpiY);
            bmp.Clear(Color.Transparent);

            var side = pixelWidth / 2;
            var side2 = side / 2;
            GcBitmap bmpLarge, bmpFlip, bmpSmall1, bmpSmall2, bmpSmall3, bmpSmall4;
            using (var bmpSrc = new GcBitmap(Path.Combine("Resources", "Stock", "goldfish.jpg")))
            {
                bmpSrc.Opaque = opaque;
                bmpLarge = bmpSrc.Resize(side, side);
                bmpFlip = bmpLarge.FlipRotate(FlipRotateAction.FlipHorizontal);
                bmpSmall1 = bmpSrc.Resize(side2, side2);
                bmpSmall2 = bmpSmall1.FlipRotate(FlipRotateAction.Rotate270);
                bmpSmall3 = bmpSmall1.FlipRotate(FlipRotateAction.FlipVertical);
                bmpSmall4 = bmpSmall1.FlipRotate(FlipRotateAction.Rotate90);
            }

            bmp.BitBlt(bmpLarge, 0, 0);
            bmp.BitBlt(bmpFlip, (int)(pixelWidth - bmpFlip.Width), 0);
            bmp.BitBlt(bmpSmall1, 0, side + side2 / 2);
            bmp.BitBlt(bmpSmall2, side2, side + side2 / 2);
            bmp.BitBlt(bmpSmall3, side2 * 2, side + side2 / 2);
            bmp.BitBlt(bmpSmall4, side2 * 3, side + side2 / 2);

            // Dispose bitmaps except the resulting one:
            bmpLarge.Dispose();
            bmpFlip.Dispose();
            bmpSmall1.Dispose();
            bmpSmall2.Dispose();
            bmpSmall3.Dispose();
            bmpSmall4.Dispose();

            return bmp;
        }
    }
}