本文整理汇总了C#中ImageMagick.MagickImage.Rotate方法的典型用法代码示例。如果您正苦于以下问题:C# MagickImage.Rotate方法的具体用法?C# MagickImage.Rotate怎么用?C# MagickImage.Rotate使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类ImageMagick.MagickImage
的用法示例。
在下文中一共展示了MagickImage.Rotate方法的8个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: Execute
public string Execute(FileItem item, string infile, string dest, ValuePairEnumerator configData)
{
var conf = new RotateTransformViewModel(configData);
// Read from file
using (MagickImage image = new MagickImage(infile))
{
image.BackgroundColor = new MagickColor(Color.Black);
if (conf.ManualRotate)
image.Rotate(item.RotationAngle);
else
{
if (conf.AutoRotate)
{
ExifProfile profile = image.GetExifProfile();
image.AutoOrient();
profile.SetValue(ExifTag.Orientation, (UInt16) 0);
}
}
if (conf.Angle > 0)
image.Rotate(conf.Angle);
if(conf.FlipHorizontal)
image.Flop();
if (conf.FlipVertical)
image.Flip();
image.Format = MagickFormat.Jpeg;
// Save the result
image.Write(dest);
}
return dest;
}
示例2: ExecuteRotate
private void ExecuteRotate(XmlElement element, MagickImage image)
{
double degrees_ = Variables.GetValue<double>(element, "degrees");
image.Rotate(degrees_);
}
示例3: RotateImage
public void RotateImage(String imgFilePath)
{
//if (File.Exists(imgFilePath))
//{
// using (Image img = Image.Load(imgFilePath))
// {
// img.RotateFlip(RotateFlipType.Rotate90FlipNone);
// img.Save();
// }
//}
if (File.Exists(imgFilePath))
{
using (MagickImage image = new MagickImage(imgFilePath))
{
image.Rotate(90.00);
image.Write(imgFilePath);
}
}
}
示例4: 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);
}
//.........这里部分代码省略.........
示例5: 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);
}
}
}
}
示例6: CopyFiles
private void CopyFiles(object o)
{
AsyncObservableCollection<FileItem> items = o as AsyncObservableCollection<FileItem>;
items = new AsyncObservableCollection<FileItem>(items.Where(file => file.IsChecked));
dlg.MaxValue = items.Count;
int i = 0;
foreach (var fileItem in items)
{
dlg.Progress = i;
dlg.ImageSource = fileItem.Thumbnail;
dlg.Label = Path.GetFileName(fileItem.FileName);
if (File.Exists(fileItem.FileName))
{
try
{
var dest = Path.Combine(destfolder, Path.GetFileName(fileItem.FileName));
if (fileItem.RotationAngle == 0)
File.Copy(fileItem.FileName, dest, true);
else
{
using (MagickImage image = new MagickImage(fileItem.FileName))
{
image.BackgroundColor = new MagickColor(Color.Black);
image.Rotate(fileItem.RotationAngle);
image.Format = MagickFormat.Jpeg;
// Save the result
image.Write(dest);
}
}
}
catch (Exception exception)
{
Log.Error("ErrorCopy file", exception);
}
}
//Thread.Sleep(100);
i++;
}
dlg.Hide();
}
示例7: RotateImage
public void RotateImage(String imgFilePath)
{
if (File.Exists(imgFilePath))
{
using (MagickImage image = new MagickImage(imgFilePath))
{
image.Rotate(90.00);
image.Write(imgFilePath);
}
}
}
示例8: Test_Rotate
public void Test_Rotate()
{
using (MagickImage image = new MagickImage(Files.Builtin.Logo))
{
Assert.AreEqual(640, image.Width);
Assert.AreEqual(480, image.Height);
image.Rotate(90);
Assert.AreEqual(480, image.Width);
Assert.AreEqual(640, image.Height);
}
}