本文整理汇总了C#中ImageMagick.MagickImage.Border方法的典型用法代码示例。如果您正苦于以下问题:C# MagickImage.Border方法的具体用法?C# MagickImage.Border怎么用?C# MagickImage.Border使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类ImageMagick.MagickImage
的用法示例。
在下文中一共展示了MagickImage.Border方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: ExecuteBorder
private void ExecuteBorder(XmlElement element, MagickImage image)
{
Hashtable arguments = new Hashtable();
foreach (XmlAttribute attribute in element.Attributes)
{
arguments[attribute.Name] = Variables.GetValue<Int32>(attribute);
}
if (OnlyContains(arguments, "size"))
image.Border((Int32)arguments["size"]);
else if (OnlyContains(arguments, "width", "height"))
image.Border((Int32)arguments["width"], (Int32)arguments["height"]);
else
throw new ArgumentException("Invalid argument combination for 'border', allowed combinations are: [size] [width, height]");
}
示例2: DrawTreeCluster
private void DrawTreeCluster(MagickImage overlay, DrawableFixture fixture)
{
//MainForm.Log(string.Format("Image: {0} ({1}) ...", fixture.Name, fixture.TreeCluster.Tree), MainForm.LogLevel.notice);
string fileName = System.IO.Path.GetFileNameWithoutExtension(fixture.TreeCluster.Tree);
string defaultTree = "elm1";
// Load model image
if (!m_modelImages.ContainsKey(fileName))
{
string treeImageFile = string.Format("{0}\\data\\prerendered\\trees\\{1}.png", System.Windows.Forms.Application.StartupPath, fileName);
if (System.IO.File.Exists(treeImageFile))
{
MagickImage modelImage = new MagickImage(treeImageFile);
modelImage.Blur();
m_modelImages.Add(fileName, modelImage);
}
else
{
MainForm.Log(string.Format("Can not find image for tree {0} ({1}), using default tree", fixture.TreeCluster.Tree, fixture.NifName), MainForm.LogLevel.warning);
m_modelImages.Add(fileName, m_modelImages[defaultTree]);
}
}
if (m_modelImages.ContainsKey(fileName) && m_modelImages[fileName] != null)
{
// Get the width of the orginal tree shape
NifRow tree = FixturesLoader.NifRows.Where(n => n.Filename.ToLower() == fixture.TreeCluster.Tree.ToLower()).FirstOrDefault();
if (tree == null) return;
System.Drawing.SizeF treeSize = tree.GetSize(0, 0);
int dimensions = ((fixture.CanvasWidth > fixture.CanvasHeight) ? fixture.CanvasWidth : fixture.CanvasHeight) + 10;
int extendedWidth = dimensions - fixture.CanvasWidth;
int extendedHeight = dimensions - fixture.CanvasHeight;
using (MagickImage treeCluster = new MagickImage(MagickColor.Transparent, dimensions, dimensions))
{
double centerX = treeCluster.Width / 2d;
double centerY = treeCluster.Height / 2d;
foreach (SharpDX.Vector3 treeInstance in fixture.TreeCluster.TreeInstances)
{
using (MagickImage treeImage = m_modelImages[fileName].Clone())
{
double scaleWidthToTreeImage = treeSize.Width / treeImage.Width;
double scaleHeightToTreeImage = treeSize.Height / treeImage.Height;
int width = Convert.ToInt32(treeImage.Width * scaleWidthToTreeImage * fixture.Scale);
int height = Convert.ToInt32(treeImage.Height * scaleHeightToTreeImage * fixture.Scale);
treeImage.Resize(width, height);
int x = Convert.ToInt32(centerX - width / 2d - zoneConfiguration.ZoneCoordinateToMapCoordinate(treeInstance.X) * (fixture.FixtureRow.Scale / 100));
int y = Convert.ToInt32(centerY - height / 2d - zoneConfiguration.ZoneCoordinateToMapCoordinate(treeInstance.Y) * (fixture.FixtureRow.Scale / 100));
treeCluster.Composite(treeImage, x, y, CompositeOperator.SrcOver);
}
}
treeCluster.Rotate((360d * fixture.FixtureRow.AxisZ3D - fixture.FixtureRow.A) * -1);
using (MagickImage modelCanvas = new MagickImage(MagickColor.Transparent, fixture.CanvasWidth, fixture.CanvasHeight))
{
foreach (DrawableElement drawableElement in fixture.DrawableElements)
{
modelCanvas.FillColor = new MagickColor(
Convert.ToUInt16(128 * 256 * drawableElement.lightning),
Convert.ToUInt16(128 * 256 * drawableElement.lightning),
Convert.ToUInt16(128 * 256 * drawableElement.lightning)
);
DrawablePolygon polyDraw = new DrawablePolygon(drawableElement.coordinates);
modelCanvas.Draw(polyDraw);
}
modelCanvas.Composite(treeCluster, Gravity.Center, CompositeOperator.DstIn);
treeCluster.Composite(modelCanvas, Gravity.Center, CompositeOperator.Overlay);
//treeCluster.Composite(modelCanvas, Gravity.Center, CompositeOperator.SrcOver);
}
if (fixture.RendererConf.HasShadow)
{
treeCluster.BorderColor = MagickColor.Transparent;
treeCluster.Border(1);
treeCluster.Shadow(
fixture.RendererConf.ShadowOffsetX,
fixture.RendererConf.ShadowOffsetY,
fixture.RendererConf.ShadowSize,
new Percentage(100 - fixture.RendererConf.ShadowTransparency),
fixture.RendererConf.ShadowColor
);
}
if (fixture.RendererConf.Transparency != 0)
{
treeCluster.Alpha(AlphaOption.Set);
double divideValue = 100.0 / (100.0 - fixture.RendererConf.Transparency);
treeCluster.Evaluate(Channels.Alpha, EvaluateOperator.Divide, divideValue);
}
overlay.Composite(treeCluster, Convert.ToInt32(fixture.CanvasX - extendedWidth/2), Convert.ToInt32(fixture.CanvasY - extendedHeight/2), CompositeOperator.SrcOver);
}
//.........这里部分代码省略.........
示例3: DrawTree
private void DrawTree(MagickImage overlay, DrawableFixture fixture)
{
System.Drawing.Color testColor = System.Drawing.ColorTranslator.FromHtml("#5e683a");
using (MagickImage pattern = new MagickImage(MagickColor.Transparent, fixture.CanvasWidth, fixture.CanvasHeight))
{
using (MagickImage patternTexture = new MagickImage(string.Format("{0}\\data\\textures\\{1}.png", System.Windows.Forms.Application.StartupPath, "leaves_mask")))
{
patternTexture.Resize(fixture.CanvasWidth / 2, fixture.CanvasHeight / 2);
pattern.Texture(patternTexture);
Random rnd = new Random();
pattern.Rotate(rnd.Next(0, 360));
using (MagickImage modelCanvas = new MagickImage(MagickColor.Transparent, fixture.CanvasWidth, fixture.CanvasHeight))
{
foreach (DrawableElement drawableElement in fixture.DrawableElements)
{
DrawablePolygon polyDraw = new DrawablePolygon(drawableElement.coordinates);
// A Shaded model without lightning is not shaded... but just we add this just be flexible
if (fixture.RendererConf.HasLight)
{
float r, g, b, light;
light = (float)drawableElement.lightning * 2f;
r = fixture.Tree.AverageColor.R * light;
g = fixture.Tree.AverageColor.G * light;
b = fixture.Tree.AverageColor.B * light;
modelCanvas.FillColor = new MagickColor(
Convert.ToUInt16(r * 255),
Convert.ToUInt16(g * 255),
Convert.ToUInt16(b * 255)
);
}
else
{
modelCanvas.FillColor = fixture.RendererConf.Color;
}
modelCanvas.Draw(polyDraw);
}
// Add leaves pattern
pattern.Composite(modelCanvas, Gravity.Center, CompositeOperator.DstIn);
modelCanvas.Composite(pattern, Gravity.Center, CompositeOperator.CopyAlpha);
if (fixture.RendererConf.HasShadow)
{
modelCanvas.BorderColor = MagickColor.Transparent;
modelCanvas.Border((int)fixture.RendererConf.ShadowSize);
modelCanvas.Shadow(
fixture.RendererConf.ShadowOffsetX,
fixture.RendererConf.ShadowOffsetY,
fixture.RendererConf.ShadowSize,
new Percentage(100 - fixture.RendererConf.ShadowTransparency),
fixture.RendererConf.ShadowColor
);
// Update the canvas position to match the new border
fixture.CanvasX -= fixture.RendererConf.ShadowSize;
fixture.CanvasY -= fixture.RendererConf.ShadowSize;
}
if (fixture.RendererConf.Transparency != 0)
{
modelCanvas.Alpha(AlphaOption.Set);
double divideValue = 100.0 / (100.0 - fixture.RendererConf.Transparency);
modelCanvas.Evaluate(Channels.Alpha, EvaluateOperator.Divide, divideValue);
}
overlay.Composite(modelCanvas, Convert.ToInt32(fixture.CanvasX), Convert.ToInt32(fixture.CanvasY), CompositeOperator.SrcOver);
}
}
}
}
示例4: DrawShaded
private void DrawShaded(MagickImage overlay, DrawableFixture fixture)
{
//MainForm.Log(string.Format("Shaded: {0} ({1}) ...", fixture.Name, fixture.NifName), MainForm.LogLevel.notice);
using (MagickImage modelCanvas = new MagickImage(MagickColor.Transparent, fixture.CanvasWidth, fixture.CanvasHeight))
{
foreach (DrawableElement drawableElement in fixture.DrawableElements)
{
DrawablePolygon polyDraw = new DrawablePolygon(drawableElement.coordinates);
// A Shaded model without lightning is not shaded... but just we add this just be flexible
if (fixture.RendererConf.HasLight)
{
modelCanvas.FillColor = new MagickColor(
Convert.ToUInt16(drawableElement.lightning * fixture.RendererConf.Color.R),
Convert.ToUInt16(drawableElement.lightning * fixture.RendererConf.Color.G),
Convert.ToUInt16(drawableElement.lightning * fixture.RendererConf.Color.B)
);
}
else
{
modelCanvas.FillColor = fixture.RendererConf.Color;
}
modelCanvas.Draw(polyDraw);
}
if (fixture.RendererConf.HasShadow)
{
modelCanvas.BorderColor = MagickColor.Transparent;
modelCanvas.Border((int)fixture.RendererConf.ShadowSize);
modelCanvas.Shadow(
fixture.RendererConf.ShadowOffsetX,
fixture.RendererConf.ShadowOffsetY,
fixture.RendererConf.ShadowSize,
new Percentage(100 - fixture.RendererConf.ShadowTransparency),
fixture.RendererConf.ShadowColor
);
// Update the canvas position to match the new border
fixture.CanvasX -= fixture.RendererConf.ShadowSize;
fixture.CanvasY -= fixture.RendererConf.ShadowSize;
}
if (fixture.RendererConf.Transparency != 0)
{
modelCanvas.Alpha(AlphaOption.Set);
double divideValue = 100.0 / (100.0 - fixture.RendererConf.Transparency);
modelCanvas.Evaluate(Channels.Alpha, EvaluateOperator.Divide, divideValue);
}
overlay.Composite(modelCanvas, Convert.ToInt32(fixture.CanvasX), Convert.ToInt32(fixture.CanvasY), CompositeOperator.SrcOver);
}
}
示例5: DrawImage
//.........这里部分代码省略.........
else m_modelImages.Add(fileName, null);
}
}
// Draw the image
if (m_modelImages.ContainsKey(fileName) && m_modelImages[fileName] != null)
{
NifRow orginalNif = FixturesLoader.NifRows.Where(n => n.NifId == fixture.FixtureRow.NifId).FirstOrDefault();
if (orginalNif == null)
{
MainForm.Log(string.Format("Error with imaged nif ({0})!", fixture.FixtureRow.TextualName), MainForm.LogLevel.warning);
}
System.Drawing.SizeF objectSize = orginalNif.GetSize(0, 0);
// The final image
using (MagickImage modelImage = new MagickImage(MagickColor.Transparent, fixture.CanvasWidth, fixture.CanvasHeight))
{
// Place the replacing image
using (MagickImage newModelImage = m_modelImages[fileName].Clone())
{
newModelImage.BackgroundColor = MagickColor.Transparent;
double scaleWidthToTreeImage = objectSize.Width / newModelImage.Width;
double scaleHeightToTreeImage = objectSize.Height / newModelImage.Height;
int width = Convert.ToInt32(newModelImage.Width * scaleWidthToTreeImage * fixture.Scale);
int height = Convert.ToInt32(newModelImage.Height * scaleHeightToTreeImage * fixture.Scale);
// Resize to new size
newModelImage.FilterType = FilterType.Gaussian;
newModelImage.VirtualPixelMethod = VirtualPixelMethod.Transparent;
newModelImage.Resize(width, height);
// Rotate the image
//newModelImage.Rotate(fixture.FixtureRow.A * -1 * fixture.FixtureRow.AxisZ3D);
newModelImage.Rotate((360d * fixture.FixtureRow.AxisZ3D - fixture.FixtureRow.A) * -1);
// Place in center of modelImage
modelImage.Composite(newModelImage, Gravity.Center, CompositeOperator.SrcOver);
}
// Draw the shaped model if wanted
if (fixture.RendererConf.HasLight)
{
using (MagickImage modelShaped = new MagickImage(MagickColor.Transparent, fixture.CanvasWidth, fixture.CanvasHeight))
{
foreach (DrawableElement drawableElement in fixture.DrawableElements)
{
var light = 1 - drawableElement.lightning;
modelShaped.FillColor = new MagickColor(
Convert.ToUInt16(ushort.MaxValue * light),
Convert.ToUInt16(ushort.MaxValue * light),
Convert.ToUInt16(ushort.MaxValue * light)
);
DrawablePolygon polyDraw = new DrawablePolygon(drawableElement.coordinates);
modelShaped.Draw(polyDraw);
}
using(MagickImage modelMask = new MagickImage(MagickColor.Transparent, fixture.CanvasWidth, fixture.CanvasHeight))
{
modelShaped.Blur();
modelMask.Composite(modelShaped, 0, 0, CompositeOperator.DstAtop);
modelMask.Composite(modelImage, 0, 0, CompositeOperator.DstIn);
modelMask.Level(new Percentage(20), new Percentage(100), Channels.All);
modelImage.Composite(modelMask, 0, 0, CompositeOperator.ColorDodge);
}
}
}
// Add the shadow if not a tree (tree shadow are substituted by a treeoverlay)
if (fixture.RendererConf.HasShadow && !fixture.IsTree)
{
modelImage.BorderColor = MagickColor.Transparent;
modelImage.Border((int)fixture.RendererConf.ShadowSize);
modelImage.Shadow(
fixture.RendererConf.ShadowOffsetX,
fixture.RendererConf.ShadowOffsetY,
fixture.RendererConf.ShadowSize,
new Percentage(100 - fixture.RendererConf.ShadowTransparency),
fixture.RendererConf.ShadowColor
);
// Update the canvas position to match the new border
fixture.CanvasX -= fixture.RendererConf.ShadowSize;
fixture.CanvasY -= fixture.RendererConf.ShadowSize;
}
// Set transprency if not a tree (see shadow)
if (fixture.RendererConf.Transparency != 0 && !fixture.IsTree)
{
double divideValue = 100.0 / (100.0 - fixture.RendererConf.Transparency);
modelImage.Evaluate(Channels.Alpha, EvaluateOperator.Divide, divideValue);
}
// Place the image on the right position
overlay.Composite(modelImage, Convert.ToInt32(fixture.CanvasX), Convert.ToInt32(fixture.CanvasY), CompositeOperator.SrcOver);
}
}
}
示例6: Test_Convolve
public void Test_Convolve()
{
using (MagickImage image = new MagickImage("xc:", 1, 1))
{
image.BorderColor = MagickColors.Black;
image.Border(5);
Assert.AreEqual(11, image.Width);
Assert.AreEqual(11, image.Height);
ConvolveMatrix matrix = new ConvolveMatrix(3, 0, 0.5, 0, 0.5, 1, 0.5, 0, 0.5, 0);
image.Convolve(matrix);
MagickColor gray = new MagickColor("#800080008000");
ColorAssert.AreEqual(MagickColors.Black, image, 4, 4);
ColorAssert.AreEqual(gray, image, 5, 4);
ColorAssert.AreEqual(MagickColors.Black, image, 6, 4);
ColorAssert.AreEqual(gray, image, 4, 5);
ColorAssert.AreEqual(MagickColors.White, image, 5, 5);
ColorAssert.AreEqual(gray, image, 6, 5);
ColorAssert.AreEqual(MagickColors.Black, image, 4, 6);
ColorAssert.AreEqual(gray, image, 5, 6);
ColorAssert.AreEqual(MagickColors.Black, image, 6, 6);
}
}