本文整理汇总了C#中ImageMagick.MagickImage.Crop方法的典型用法代码示例。如果您正苦于以下问题:C# MagickImage.Crop方法的具体用法?C# MagickImage.Crop怎么用?C# MagickImage.Crop使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类ImageMagick.MagickImage
的用法示例。
在下文中一共展示了MagickImage.Crop方法的12个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: Execute
public string Execute(FileItem item, string infile, string dest, ValuePairEnumerator configData)
{
var conf = new CropTransformViewModel(configData);
using (MagickImage image = new MagickImage(infile))
{
if (conf.FromLiveView && ServiceProvider.DeviceManager.SelectedCameraDevice != null)
{
var prop = ServiceProvider.DeviceManager.SelectedCameraDevice.LoadProperties();
conf.Left = (int) (image.Width*prop.LiveviewSettings.HorizontalMin/100);
conf.Width = (image.Width*
(prop.LiveviewSettings.HorizontalMax - prop.LiveviewSettings.HorizontalMin)/100);
conf.Top = (image.Height*prop.LiveviewSettings.VerticalMin/100);
conf.Height = (image.Height*(prop.LiveviewSettings.VerticalMax - prop.LiveviewSettings.VerticalMin)/
100);
}
if (conf.CropMargins)
{
conf.Left = image.Width * conf.WidthProcent / 100;
conf.Width = image.Width - (conf.Left*2);
conf.Top = image.Height * conf.HeightProcent / 100;
conf.Height = image.Height - (conf.Top*2);
}
MagickGeometry geometry = new MagickGeometry();
geometry.Width = conf.Width;
geometry.Height = conf.Height;
geometry.X = conf.Left;
geometry.Y = conf.Top;
image.Crop(geometry);
image.Format = MagickFormat.Jpeg;
image.Write(dest);
}
return dest;
}
示例2: Execute
public async Task<ValidationResult> Execute(MediaInfo mediaInfo, Int32 x, Int32 y, Int32 width, Int32 height)
{
if (x < 0 || y < 0 || width <= 0 || height <= 0)
{
return new ValidationResult("サイズの指定が不正です。");
}
var mediaContent = await _mediaRepository.Get(mediaInfo);
if (mediaContent == null)
{
return new ValidationResult("指定されたメディアが見つかりませんでした。");
}
var data = await mediaContent.GetContentAsync();
var imageInfo = new MagickImageInfo(data);
if (imageInfo.Width < (x + width) || imageInfo.Height < (y + height))
{
return new ValidationResult("指定されたサイズは画像のサイズを超えています。");
}
// リサイズするよ!
using (var image = new MagickImage(data))
{
image.Crop(new MagickGeometry(x, y, width, height));
image.Page = new MagickGeometry(0, 0, width, height);
// そして更新
await _mediaRepository.Update(mediaInfo, image.ToByteArray());
}
return ValidationResult.Success;
}
示例3: CreateSketchesPath
/// <summary>
/// Returns the path to the sketch image just created
/// <param name="mask">Mask image of the button</param>
/// <param name="texture">Texture image of the item</param>
/// <param name="nameSketch">Name of the image to create</param>
public static string CreateSketchesPath(string mask, string texture, string nameSketch)
{
MagickImage Mask = new MagickImage(mask);
MagickImage Texture = new MagickImage(texture);
Texture.Crop(Mask.Width, Mask.Height);
Texture.Composite(Mask, CompositeOperator.CopyAlpha);
Mask.Composite(Texture, CompositeOperator.Multiply);
MagickImage sketch = Mask;
try
{
// sketch.Write(Helpers.ResourcesHelper.SketchesPath() + nameSketch);
string p = Helpers.ResourcesHelper.SketchesPath() + nameSketch;
System.IO.Stream s = new System.IO.FileStream(p, System.IO.FileMode.Create);
sketch.Write(s);
s.Close();
}
catch (MagickException ex)
{
string s= ex.Message;
}
catch
{
}
sketch.Dispose();
sketch = null;
string path = Helpers.ResourcesHelper.SketchesPath() + nameSketch;
return path;
}
示例4: crop
public static void crop(string image_path, string output_path, Tuple<int, int> from, Tuple<int, int> to)
{
using (MagickImage image = new MagickImage(image_path)) {
image.Crop(new MagickGeometry(from.Item1, from.Item2, to.Item1 - from.Item1, to.Item2 - from.Item2));
image.Write(output_path);
}
}
示例5: Compare
public double Compare(MagickImage leftImage, MagickImage rightImage, out MagickImage diffImage)
{
// See:
// [1] https://stackoverflow.com/questions/5132749/diff-an-image-using-imagemagick
// [2] https://stackoverflow.com/questions/20582620/how-to-compare-2-images-ignoring-areas#26584462
// resize image to the same size - ImageMagick requires both images to be of the same size
rightImage.Crop(leftImage.BaseWidth, leftImage.BaseHeight);
// apply the mask to the screenshot
rightImage.Composite(leftImage, CompositeOperator.DstIn);
// compare masked screenshot against reference image
diffImage = new MagickImage();
return rightImage.Compare(leftImage, ErrorMetric.Absolute, diffImage);
}
示例6: Execute
public string Execute(FileItem item, string infile, string dest, ValuePairEnumerator configData)
{
var conf = new PixelBinningViewModel(configData);
dest = Path.Combine(Path.GetDirectoryName(dest), Path.GetFileNameWithoutExtension(dest) + ".jpg");
using (MagickImage image = new MagickImage(infile))
{
int newx = image.Width/(conf.SelectedMode + 2);
int newy = image.Height / (conf.SelectedMode + 2);
int cropx = newx * (conf.SelectedMode + 2);
int cropy = newy * (conf.SelectedMode + 2);
if (cropx != image.Width || cropy != image.Height)
image.Crop(cropx, cropy, Gravity.Center);
image.FilterType = FilterType.Box;
image.Resize(newx,newy);
image.Format = MagickFormat.Jpeg;
image.Write(dest);
}
return dest;
}
示例7: CopyFile
public void CopyFile(string filename, string destFile)
{
using (MagickImage image = new MagickImage(filename))
{
double zw = (double)Width / image.Width;
double zh = (double)Height /image.Height;
double za = FillImage ? ((zw <= zh) ? zw : zh) : ((zw >= zh) ? zw : zh);
if (FillImage)
{
double aspect = (double) VideoType.Width/VideoType.Height;
double pAspect = (double) image.Width/image.Height;
if (aspect > pAspect)
image.Crop(image.Width, (int) (image.Width/aspect), Gravity.Center);
else
image.Crop((int) (image.Height/aspect), image.Height, Gravity.Center);
}
MagickGeometry geometry = new MagickGeometry(VideoType.Width, VideoType.Height)
{
IgnoreAspectRatio = false,
FillArea = false
};
image.FilterType = FilterType.Point;
image.Resize(geometry);
image.Quality = 80;
image.Format = MagickFormat.Jpeg;
image.Write(destFile);
}
}
示例8: ExecuteCrop
private void ExecuteCrop(XmlElement element, MagickImage image)
{
Hashtable arguments = new Hashtable();
foreach (XmlAttribute attribute in element.Attributes)
{
if (attribute.Name == "geometry")
arguments["geometry"] = Variables.GetValue<MagickGeometry>(attribute);
else if (attribute.Name == "gravity")
arguments["gravity"] = Variables.GetValue<Gravity>(attribute);
else if (attribute.Name == "height")
arguments["height"] = Variables.GetValue<Int32>(attribute);
else if (attribute.Name == "width")
arguments["width"] = Variables.GetValue<Int32>(attribute);
else if (attribute.Name == "x")
arguments["x"] = Variables.GetValue<Int32>(attribute);
else if (attribute.Name == "y")
arguments["y"] = Variables.GetValue<Int32>(attribute);
}
if (OnlyContains(arguments, "geometry"))
image.Crop((MagickGeometry)arguments["geometry"]);
else if (OnlyContains(arguments, "width", "height"))
image.Crop((Int32)arguments["width"], (Int32)arguments["height"]);
else if (OnlyContains(arguments, "width", "height", "gravity"))
image.Crop((Int32)arguments["width"], (Int32)arguments["height"], (Gravity)arguments["gravity"]);
else if (OnlyContains(arguments, "x", "y", "width", "height"))
image.Crop((Int32)arguments["x"], (Int32)arguments["y"], (Int32)arguments["width"], (Int32)arguments["height"]);
else
throw new ArgumentException("Invalid argument combination for 'crop', allowed combinations are: [geometry] [width, height] [width, height, gravity] [x, y, width, height]");
}
示例9: 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);
//////////////////////////////////////////
}
示例10: ApplyPreviewImageMagick
public static void ApplyPreviewImageMagick(string source, string destination, double maxWidth = 0d, double maxHeight = 0d) {
using (var image = new MagickImage(source)) {
if (maxWidth > 0d || maxHeight > 0d) {
var k = Math.Max(maxHeight / image.Height, maxWidth / image.Width);
image.Interpolate = PixelInterpolateMethod.Bicubic;
image.FilterType = FilterType.Lanczos;
image.Sharpen();
image.Resize((int)(k * image.Width), (int)(k * image.Height));
image.Crop(CommonAcConsts.PreviewWidth, CommonAcConsts.PreviewHeight, Gravity.Center);
}
image.Quality = 95;
image.Density = new MagickGeometry(96, 96);
if (File.Exists(destination)) {
try {
File.Delete(destination);
} catch (UnauthorizedAccessException) {
Thread.Sleep(200);
File.Delete(destination);
}
}
image.Write(destination);
}
}
示例11: Test_CannyEdge_HoughLine
public void Test_CannyEdge_HoughLine()
{
using (MagickImage image = new MagickImage(Files.ConnectedComponentsPNG))
{
image.Threshold(new Percentage(50));
ColorAssert.AreEqual(MagickColors.Black, image, 150, 365);
image.Negate();
ColorAssert.AreEqual(MagickColors.White, image, 150, 365);
image.CannyEdge();
ColorAssert.AreEqual(MagickColors.Black, image, 150, 365);
image.Crop(260, 180, 215, 200);
image.Settings.FillColor = MagickColors.Red;
image.Settings.StrokeColor = MagickColors.Red;
image.HoughLine();
ColorAssert.AreEqual(MagickColors.Red, image, 105, 25);
}
}
示例12: takeSnapshot
protected MagickImage takeSnapshot(IWebElement webElement, int offset)
{
try
{
Screenshot image = ((ITakesScreenshot)pageManager.driver).GetScreenshot();
MagickImage MImage = new MagickImage(image.AsByteArray);
Point coords = (webElement as ILocatable).LocationOnScreenOnceScrolledIntoView;
// MagickGeometry n = new MagickGeometry(webElement.Location.X - offset, webElement.Location.Y - offset, webElement.Size.Width + 2 * offset, webElement.Size.Height + 2 * offset);
MagickGeometry n = new MagickGeometry(coords.X - offset, coords.Y - offset, webElement.Size.Width + 2 * offset, webElement.Size.Height + 2 * offset);
MImage.Crop(n);
return MImage;
}
catch
{
Console.Out.WriteLine("Ошибка при снятии скриншота");
return null;
}
}