本文整理汇总了C#中ImageMagick.MagickImage.Clone方法的典型用法代码示例。如果您正苦于以下问题:C# MagickImage.Clone方法的具体用法?C# MagickImage.Clone怎么用?C# MagickImage.Clone使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类ImageMagick.MagickImage
的用法示例。
在下文中一共展示了MagickImage.Clone方法的12个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: PartOfImage
public static List<PartOfImage> PartOfImage(string ImgUrl, string onlyFileName, int pxFormat)
{
List<PartOfImage> ImgsInfo = new List<Api._QPR.PartOfImage>();
//resize with pixformat
MagickImage img = new MagickImage(ImgUrl);
int _w = img.Width;
int _h = img.Height;
int partWComp = (_w / UserProperty.ComputerNumber);
int partHComp = (_h / UserProperty.ComputerNumber);
int PartWPixFormat = (partWComp / pxFormat);
int PartHPixFormat = (partHComp / pxFormat);
int newPartWcomp = PartWPixFormat * pxFormat;
int newPartHcomp = PartHPixFormat * pxFormat;
int newW = newPartWcomp * UserProperty.ComputerNumber;
int newH = newPartHcomp * UserProperty.ComputerNumber;
String newGeomStr = newW.ToString() + "x" + newH.ToString();
MagickGeometry intermediate_geo = new MagickGeometry(newGeomStr);
img.Crop(intermediate_geo);
string partImgFolder = Path.Combine(UserProperty.ResourcePhotos_Path, "ImagePart");
if (!Directory.Exists(partImgFolder))
{
Directory.CreateDirectory(partImgFolder);
}
if (_w >= _h)
{
int cont = 0;
do
{
Rectangle recti = new Rectangle(cont * (newW / UserProperty.ComputerNumber), 0, (newW / UserProperty.ComputerNumber), newH);
MagickGeometry intermediate_geo1 = new MagickGeometry(recti);
MagickImage newPartImg = img.Clone();
newPartImg.Crop(intermediate_geo1);
string file = Path.Combine(partImgFolder, "output_" + cont + ImageProperty.JPG);
newPartImg.Write(file);
ImgsInfo.Add(new Api._QPR.PartOfImage(file, recti));
cont++;
} while (cont < UserProperty.ComputerNumber);
}
else
{
int cont = 0;
do
{
Rectangle recti = new Rectangle(0, cont * (newH / UserProperty.ComputerNumber), newW, (newH / UserProperty.ComputerNumber));
MagickGeometry intermediate_geo1 = new MagickGeometry(recti);
MagickImage newPartImg = img.Clone();
newPartImg.Crop(intermediate_geo1);
string file = Path.Combine(partImgFolder, onlyFileName + "_" + cont + ImageProperty.JPG);
newPartImg.Write(file);
ImgsInfo.Add(new Api._QPR.PartOfImage(file, recti));
cont++;
} while (cont < UserProperty.ComputerNumber);
}
return ImgsInfo;
//img.Write(UserProperty.ResourcePhotos_Path + "\\" + imgNamei + "1" + ImageProperty.JPG);
//////////////////////////////////////////
}
示例2: Test_Composite_ChangeMask
public void Test_Composite_ChangeMask()
{
using (MagickImage background = new MagickImage("xc:red", 100, 100))
{
background.BackgroundColor = Color.White;
background.Extent(200, 100);
IDrawable[] drawables = new IDrawable[]
{
new DrawablePointSize(50),
new DrawableText(135, 70, "X")
};
using (MagickImage image = background.Clone())
{
image.Draw(drawables);
image.Composite(background, Gravity.Center, CompositeOperator.ChangeMask);
using (MagickImage result = new MagickImage(MagickColor.Transparent, 200, 100))
{
result.Draw(drawables);
Assert.AreEqual(0.073, result.Compare(image, ErrorMetric.RootMeanSquared), 0.001);
}
}
}
}
示例3: ExecuteClone
private void ExecuteClone(XmlElement element, MagickImage image)
{
Execute(element, image.Clone());
}
示例4: Test_Clone_Area
public void Test_Clone_Area()
{
using (MagickImage icon = new MagickImage(Files.MagickNETIconPNG))
{
using (MagickImage area = icon.Clone())
{
area.Crop(64, 64, Gravity.Southeast);
area.RePage();
Assert.AreEqual(64, area.Width);
Assert.AreEqual(64, area.Height);
area.Crop(64, 32, Gravity.North);
Assert.AreEqual(64, area.Width);
Assert.AreEqual(32, area.Height);
using (MagickImage part = icon.Clone(new MagickGeometry(64, 64, 64, 32)))
{
Test_Clone_Area(area, part);
}
using (MagickImage part = icon.Clone(64, 64, 64, 32))
{
Test_Clone_Area(area, part);
}
}
using (MagickImage area = icon.Clone())
{
area.Crop(32, 64, Gravity.Northwest);
Assert.AreEqual(32, area.Width);
Assert.AreEqual(64, area.Height);
using (MagickImage part = icon.Clone(32, 64))
{
Test_Clone_Area(area, part);
}
}
using (MagickImage area = icon.Clone(4, 2))
{
Assert.AreEqual(4, area.Width);
Assert.AreEqual(2, area.Height);
ExceptionAssert.Throws<MagickMissingDelegateErrorException>(delegate ()
{
area.ToByteArray();
});
#if Q8
Assert.AreEqual(32, area.ToByteArray(MagickFormat.Rgba).Length);
#elif Q16 || Q16HDRI
Assert.AreEqual(64, area.ToByteArray(MagickFormat.Rgba).Length);
#else
#error Not implemented!
#endif
}
}
}
示例5: Test_Compare
public void Test_Compare()
{
MagickImage first = new MagickImage(Files.SnakewarePNG);
MagickImage second = first.Clone();
MagickErrorInfo same = first.Compare(second);
Assert.IsNotNull(same);
Assert.AreEqual(0, same.MeanErrorPerPixel);
double distortion = first.Compare(second, ErrorMetric.Absolute);
Assert.AreEqual(0, distortion);
first.Threshold(new Percentage(50));
MagickErrorInfo different = first.Compare(second);
Assert.IsNotNull(different);
Assert.AreNotEqual(0, different.MeanErrorPerPixel);
distortion = first.Compare(second, ErrorMetric.Absolute);
Assert.AreNotEqual(0, distortion);
MagickImage difference = new MagickImage();
distortion = first.Compare(second, ErrorMetric.RootMeanSquared, difference);
Assert.AreNotEqual(0, distortion);
Assert.AreNotEqual(first, difference);
Assert.AreNotEqual(second, difference);
}
示例6: Test_Compare
public void Test_Compare()
{
MagickImage first = new MagickImage(Files.ImageMagickJPG);
ExceptionAssert.Throws<ArgumentNullException>(delegate ()
{
first.Compare(null);
});
MagickImage second = first.Clone();
MagickErrorInfo same = first.Compare(second);
Assert.IsNotNull(same);
Assert.AreEqual(0, same.MeanErrorPerPixel);
double distortion = first.Compare(second, ErrorMetric.Absolute);
Assert.AreEqual(0, distortion);
first.Threshold(new Percentage(50));
MagickErrorInfo different = first.Compare(second);
Assert.IsNotNull(different);
Assert.AreNotEqual(0, different.MeanErrorPerPixel);
distortion = first.Compare(second, ErrorMetric.Absolute);
Assert.AreNotEqual(0, distortion);
MagickImage difference = new MagickImage();
distortion = first.Compare(second, ErrorMetric.RootMeanSquared, difference);
Assert.AreNotEqual(0, distortion);
Assert.AreNotEqual(first, difference);
Assert.AreNotEqual(second, difference);
second.Dispose();
first.Opaque(MagickColors.Black, MagickColors.Green);
first.Opaque(MagickColors.White, MagickColors.Green);
second = first.Clone();
second.FloodFill(MagickColors.Gray, 0, 0);
distortion = first.Compare(second, ErrorMetric.Absolute, Channels.Green);
Assert.AreEqual(0, distortion);
distortion = first.Compare(second, ErrorMetric.Absolute, Channels.Red);
Assert.AreNotEqual(0, distortion);
}
示例7: Test_Clone
public void Test_Clone()
{
using (MagickImage first = new MagickImage(Files.SnakewarePNG))
{
using (MagickImage second = first.Clone())
{
Test_Clone(first, second);
}
using (MagickImage second = new MagickImage(first))
{
Test_Clone(first, second);
}
}
}
示例8: Test_Clone_Area
public void Test_Clone_Area()
{
using (MagickImage icon = new MagickImage(Files.MagickNETIconPNG))
{
using (MagickImage area = icon.Clone())
{
area.Crop(64, 64, Gravity.Southeast);
area.RePage();
Assert.AreEqual(64, area.Width);
Assert.AreEqual(64, area.Height);
area.Crop(64, 32, Gravity.North);
Assert.AreEqual(64, area.Width);
Assert.AreEqual(32, area.Height);
using (MagickImage part = icon.Clone(new MagickGeometry(64, 64, 64, 32)))
{
Test_Clone_Area(area, part);
}
using (MagickImage part = icon.Clone(64, 64, 64, 32))
{
Test_Clone_Area(area, part);
}
}
using (MagickImage area = icon.Clone())
{
area.Crop(32, 64, Gravity.Northwest);
Assert.AreEqual(32, area.Width);
Assert.AreEqual(64, area.Height);
using (MagickImage part = icon.Clone(32, 64))
{
Test_Clone_Area(area, part);
}
}
using (MagickImage area = icon.Clone(4, 2))
{
Assert.AreEqual(4, area.Width);
Assert.AreEqual(2, area.Height);
Assert.AreEqual(64, area.ToByteArray(MagickFormat.Rgba).Length);
}
}
}
示例9: Test_Encipher_Decipher
public void Test_Encipher_Decipher()
{
using (MagickImage original = new MagickImage(Files.SnakewarePNG))
{
using (MagickImage enciphered = original.Clone())
{
enciphered.Encipher("All your base are belong to us");
Assert.AreNotEqual(original, enciphered);
using (MagickImage deciphered = enciphered.Clone())
{
deciphered.Decipher("What you say!!");
Assert.AreNotEqual(enciphered, deciphered);
Assert.AreNotEqual(original, deciphered);
}
using (MagickImage deciphered = enciphered.Clone())
{
deciphered.Decipher("All your base are belong to us");
Assert.AreNotEqual(enciphered, deciphered);
Assert.AreEqual(original, deciphered);
}
}
}
}
示例10: Test_CycleColormap
public void Test_CycleColormap()
{
using (MagickImage first = new MagickImage(Files.Builtin.Logo))
{
Assert.AreEqual(256, first.ColormapSize);
using (MagickImage second = first.Clone())
{
second.CycleColormap(128);
Assert.AreNotEqual(first, second);
second.CycleColormap(128);
Assert.AreEqual(first, second);
second.CycleColormap(256);
Assert.AreEqual(first, second);
second.CycleColormap(512);
Assert.AreEqual(first, second);
}
}
}
示例11: Test_Component
private void Test_Component(MagickImage image, ConnectedComponent component, int x, int y, int width, int height)
{
int delta = 2;
Assert.AreEqual(x, component.X, delta);
Assert.AreEqual(y, component.Y, delta);
Assert.AreEqual(width, component.Width, delta);
Assert.AreEqual(height, component.Height, delta);
using (MagickImage area = image.Clone())
{
area.Crop(component.ToGeometry(10));
Assert.AreEqual(width + 20, area.Width, delta);
Assert.AreEqual(height + 20, area.Height, delta);
}
}
示例12: Test_ConnectedComponents
public void Test_ConnectedComponents()
{
using (MagickImage image = new MagickImage(Files.ConnectedComponentsPNG))
{
using (MagickImage temp = image.Clone())
{
temp.Blur(0, 10);
temp.Threshold((Percentage)50);
ConnectedComponent[] components = temp.ConnectedComponents(4).OrderBy(c => c.X).ToArray();
Assert.AreEqual(7, components.Length);
Assert.IsNull(temp.GetArtifact("connected-components:area-threshold"));
Assert.IsNull(temp.GetArtifact("connected-components:mean-color"));
Test_Component(image, components[1], 94, 297, 128, 151);
Test_Component(image, components[2], 99, 554, 128, 150);
Test_Component(image, components[3], 267, 432, 89, 139);
Test_Component(image, components[4], 301, 202, 148, 143);
Test_Component(image, components[5], 341, 622, 136, 150);
Test_Component(image, components[6], 434, 411, 88, 139);
}
#if !Q8
using (MagickImage temp = image.Clone())
{
ConnectedComponentsSettings settings = new ConnectedComponentsSettings()
{
Connectivity = 4,
MeanColor = true,
AreaThreshold = 400
};
ConnectedComponent[] components = temp.ConnectedComponents(settings).OrderBy(c => c.X).ToArray();
Assert.AreEqual(13, components.Length);
Assert.IsNotNull(temp.GetArtifact("connected-components:area-threshold"));
Assert.IsNotNull(temp.GetArtifact("connected-components:mean-color"));
Test_Component(image, components[1], 90, 293, 139, 162);
Test_Component(image, components[2], 96, 550, 138, 162);
Test_Component(image, components[3], 213, 633, 1, 2);
Test_Component(image, components[4], 215, 637, 3, 1);
Test_Component(image, components[5], 217, 641, 3, 1);
Test_Component(image, components[6], 219, 645, 3, 1);
Test_Component(image, components[7], 221, 647, 3, 1);
Test_Component(image, components[8], 268, 433, 89, 139);
Test_Component(image, components[9], 298, 198, 155, 151);
Test_Component(image, components[10], 337, 618, 148, 158);
Test_Component(image, components[11], 410, 247, 2, 1);
Test_Component(image, components[12], 434, 411, 88, 140);
}
#endif
}
}