//
// 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 System.Numerics;
using GrapeCity.Documents.Drawing;
using GrapeCity.Documents.Text;
using GrapeCity.Documents.Imaging;
using GCTEXT = GrapeCity.Documents.Text;
using GCDRAW = GrapeCity.Documents.Drawing;
using DsImagingWeb.Demos.Common;
namespace DsImagingWeb.Demos
{
// This example uses the GaussianBlurEffect to draw semi-transparent colored circles ('filters'),
// blurring the portion of the image behind them.
public class GaussianBlur2
{
public GcBitmap GenerateImage(Size pixelSize, float dpi, bool opaque, string[] sampleParams = null)
{
var colors = new Color[]
{
Color.Fuchsia,
Color.Orange,
Color.Black,
Color.Blue,
Color.Red,
Color.Yellow,
Color.White,
Color.Green,
Color.CornflowerBlue
};
colors.Shuffle();
var imagePath = Path.Combine("Resources", "ImagesBis", "bahamas.jpg");
var bmp = new GcBitmap(imagePath);
int xx = bmp.PixelWidth / 3;
int yy = bmp.PixelHeight / 3;
int maxr = Math.Min(xx / 2, yy / 2);
var rnd = Util.NewRandom();
using var bmpBk = bmp.Clone();
// Apply blur to a copy of the original bitmap:
bmpBk.ApplyEffect(GaussianBlurEffect.Get(24, GaussianBlurBorderMode.RepeatEdge));
using var g = bmp.CreateGraphics();
var renderer = g.Renderer;
for (int i = 0; i < 9; i++)
{
int r = rnd.Next(maxr / 3, maxr);
var center = new PointF(rnd.Next(r, xx - r) + i % 3 * xx + 1, rnd.Next(r, yy - r) + i / 3 * yy + 1);
var rect = new RectangleF(center.X - r, center.Y - r, r + r, r + r);
var color = colors[i];
// Use the blurred background to fill circles:
renderer.BackgroundBitmap = bmpBk;
g.FillEllipse(rect, Color.FromArgb(96, color));
// Draw borders normally to hide the artifacts:
renderer.BackgroundBitmap = null;
g.DrawEllipse(rect, new GCDRAW.Pen(color, 2));
}
return bmp;
}
}
}