//
// This code is part of Document Solutions for Imaging demos.
// Copyright (c) MESCIUS 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 DsImagingWeb.Demos
{
// This sample demonstrates how to use bitmap transformations
// such as resizing, flipping and rotating.
public class Transforms
{
public GcBitmap GenerateImage(Size pixelSize, float dpi, bool opaque, string[] sampleParams = null)
{
var bmp = new GcBitmap(pixelSize.Width, pixelSize.Height, opaque, dpi, dpi);
bmp.Clear(Color.Transparent);
var side = pixelSize.Width / 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)(pixelSize.Width - 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;
}
}
}