本文整理汇总了C#中ImageMagick.MagickImage.Annotate方法的典型用法代码示例。如果您正苦于以下问题:C# MagickImage.Annotate方法的具体用法?C# MagickImage.Annotate怎么用?C# MagickImage.Annotate使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类ImageMagick.MagickImage
的用法示例。
在下文中一共展示了MagickImage.Annotate方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: Test_Affine
public void Test_Affine()
{
using (MagickImage image = new MagickImage(MagickColors.White, 300, 300))
{
Assert.AreEqual(null, image.Settings.Affine);
image.Annotate("Magick.NET", Gravity.Center);
ColorAssert.AreEqual(MagickColors.White, image, 200, 200);
image.Settings.Affine = new DrawableAffine(10, 20, 30, 40, 50, 60);
image.Annotate("Magick.NET", Gravity.Center);
ColorAssert.AreEqual(MagickColors.Black, image, 200, 200);
}
}
示例2: ExecuteAnnotate
private void ExecuteAnnotate(XmlElement element, MagickImage image)
{
Hashtable arguments = new Hashtable();
foreach (XmlAttribute attribute in element.Attributes)
{
if (attribute.Name == "angle")
arguments["angle"] = Variables.GetValue<double>(attribute);
else if (attribute.Name == "boundingArea")
arguments["boundingArea"] = Variables.GetValue<MagickGeometry>(attribute);
else if (attribute.Name == "gravity")
arguments["gravity"] = Variables.GetValue<Gravity>(attribute);
else if (attribute.Name == "text")
arguments["text"] = Variables.GetValue<String>(attribute);
}
if (OnlyContains(arguments, "text", "boundingArea"))
image.Annotate((String)arguments["text"], (MagickGeometry)arguments["boundingArea"]);
else if (OnlyContains(arguments, "text", "boundingArea", "gravity"))
image.Annotate((String)arguments["text"], (MagickGeometry)arguments["boundingArea"], (Gravity)arguments["gravity"]);
else if (OnlyContains(arguments, "text", "boundingArea", "gravity", "angle"))
image.Annotate((String)arguments["text"], (MagickGeometry)arguments["boundingArea"], (Gravity)arguments["gravity"], (double)arguments["angle"]);
else if (OnlyContains(arguments, "text", "gravity"))
image.Annotate((String)arguments["text"], (Gravity)arguments["gravity"]);
else
throw new ArgumentException("Invalid argument combination for 'annotate', allowed combinations are: [text, boundingArea] [text, boundingArea, gravity] [text, boundingArea, gravity, angle] [text, gravity]");
}
示例3: Main
static void Main(string[] args)
{
string searchQuery = System.Windows.Forms.Clipboard.GetText();
using (MagickImageCollection animation = new MagickImageCollection()) //Very few cartoons are broadcast live it's a terrible strain on the animators wrist.
using (WebClient wc = new WebClient()) //The Internet, eh?
{
//Check the query
List<a_lengthly_inefficient_search_at_the_taxpayers_expense> searchResult
= JsonConvert.DeserializeObject<List<a_lengthly_inefficient_search_at_the_taxpayers_expense>>
(wc.DownloadString(Frinkiac.API_Root + "search?q=" + searchQuery.Replace(" ", "%20")));
if (searchResult.Count <= resultIndex) //Bad grammar overload.
throw new IndexOutOfRangeException("search string " + searchQuery + " not found");
//Retrieve captions associated with result
childrens_letters_to_god captionResult = JsonConvert.DeserializeObject<childrens_letters_to_god>(wc.DownloadString(Frinkiac.API_Root
+ "caption?e=" + searchResult[resultIndex].Episode
+ "&t=" + searchResult[resultIndex].Timestamp));
while (frameBatches > 0)
{
foreach (an_arm_drawn_by_nobody_it_is_worth_nothing frame in captionResult.Neighboreenos)
{ //request each frame in captionQuery and add to our MagickImageCollection for the animation
MagickImage frameImage = new MagickImage(wc.DownloadData(Frinkiac.IMG_Root
+ frame.Episode + "/"
+ frame.Timestamp + ".jpg"), new MagickReadSettings());
frameImage.AnimationDelay = 20;
foreach (Anifrinkiac.you_egghead_writers_wouldve_never_thought_of_it caption in captionResult.Subtitles) //Check out the subtitle results
if ((frame.Timestamp > caption.StartTimestamp)
&& (frame.Timestamp < caption.EndTimestamp))
frameImage.Annotate(caption.Content, Gravity.South); //Apply captions
animation.Add(frameImage);
} //Retrieve the next set of frames
if (frameBatches-- > 0)
{
captionResult = JsonConvert.DeserializeObject<childrens_letters_to_god>(wc.DownloadString(Frinkiac.API_Root
+ "caption?e=" + searchResult[resultIndex].Episode
+ "&t=" + captionResult.Neighboreenos[captionResult.Neighboreenos.Count - 1].Timestamp));
//Do it again for all new frames
captionResult = JsonConvert.DeserializeObject<childrens_letters_to_god>(wc.DownloadString(Frinkiac.API_Root
+ "caption?e=" + searchResult[resultIndex].Episode
+ "&t=" + captionResult.Neighboreenos[captionResult.Neighboreenos.Count - 1].Timestamp));
}
}
// Optionally reduce colors
QuantizeSettings settings = new QuantizeSettings();
settings.Colors = 256;
animation.Quantize(settings);
// Optionally optimize the images (images should have the same size).
animation.Optimize();
//Upload gif to imgur
wc.Headers.Add("Authorization", "Client-ID " + System.Configuration.ConfigurationManager.AppSettings["imgurClientID"].ToString());
NameValueCollection values = new NameValueCollection
{
{ "image", Convert.ToBase64String(animation.ToByteArray(MagickFormat.Gif)) }
};
//Deserialize the xml reply
XDocument reply = XDocument.Load(new MemoryStream(wc.UploadValues("https://api.imgur.com/3/upload.xml", values)));
//Give up the goods
System.Console.WriteLine(reply.Root.Element("link"));
System.Windows.Forms.Clipboard.SetText(reply.Root.Element("link").Value + " : " + searchQuery);
}
}
示例4: Test_Annotate
public void Test_Annotate()
{
using (MagickImage image = new MagickImage(MagickColors.Thistle, 200, 50))
{
image.Settings.FontPointsize = 20;
image.Settings.FillColor = MagickColors.Purple;
image.Settings.StrokeColor = MagickColors.Purple;
image.Annotate("Magick.NET", Gravity.East);
ColorAssert.AreEqual(MagickColors.Purple, image, 197, 17);
ColorAssert.AreEqual(MagickColors.Thistle, image, 174, 17);
}
using (MagickImage image = new MagickImage(MagickColors.GhostWhite, 200, 200))
{
image.Settings.FontPointsize = 30;
image.Settings.FillColor = MagickColors.Orange;
image.Settings.StrokeColor = MagickColors.Orange;
image.Annotate("Magick.NET", new MagickGeometry(75, 125, 0, 0), Gravity.Undefined, 45);
ColorAssert.AreEqual(MagickColors.GhostWhite, image, 104, 83);
ColorAssert.AreEqual(MagickColors.Orange, image, 118, 70);
}
}
示例5: Test_TextAntiAlias
public void Test_TextAntiAlias()
{
using (MagickImage image = new MagickImage(MagickColors.Azure, 300, 300))
{
Assert.AreEqual(true, image.Settings.TextAntiAlias);
image.Settings.TextAntiAlias = false;
image.Settings.FontPointsize = 100;
image.Annotate("TEST", Gravity.Center);
ColorAssert.AreEqual(MagickColors.Azure, image, 175, 112);
}
}
示例6: ExecuteThread
public string ExecuteThread(FileItem item, string infile, string dest, ValuePairEnumerator configData)
{
var conf = new OverlayTransformViewModel(configData);
using (MagickImage image = new MagickImage(infile))
{
Gravity gravity = Gravity.Center;
if (conf.A11)
{
gravity = Gravity.Northwest;
}
if (conf.A12)
{
gravity = Gravity.North;
}
if (conf.A13)
{
gravity = Gravity.Northeast;
}
if (conf.A21)
{
gravity = Gravity.West;
}
if (conf.A22)
{
gravity = Gravity.Center;
}
if (conf.A23)
{
gravity = Gravity.East;
}
if (conf.A31)
{
gravity = Gravity.Southwest;
}
if (conf.A32)
{
gravity = Gravity.South;
}
if (conf.A33)
{
gravity = Gravity.Southeast;
}
if (File.Exists(conf.OverlayFile))
{
// Read the watermark that will be put on top of the image
using (MagickImage watermark = new MagickImage(conf.OverlayFile))
{
if (conf.StrechOverlay)
watermark.Resize(image.Width, image.Height);
// Optionally make the watermark more transparent
if (conf.Transparency != 100)
watermark.Evaluate(Channels.Alpha, EvaluateOperator.Add,
-(255*(100 - conf.Transparency)/100));
// Draw the watermark in the bottom right corner
image.Composite(watermark, gravity, CompositeOperator.Over);
//// Optionally make the watermark more transparent
//watermark.Evaluate(Channels.Alpha, EvaluateOperator.Divide, 4);
//// Or draw the watermark at a specific location
//image.Composite(watermark, 200, 50, CompositeOperator.Over);
}
}
string text = "";
if (!string.IsNullOrEmpty(conf.Text))
{
Regex regPattern = new Regex(@"\[(.*?)\]", RegexOptions.Singleline);
MatchCollection matchX = regPattern.Matches(conf.Text);
text = matchX.Cast<Match>()
.Aggregate(conf.Text,
(current1, match) =>
item.FileNameTemplates.Where(
template =>
String.Compare(template.Name, match.Value,
StringComparison.InvariantCultureIgnoreCase) == 0).Aggregate(current1,
(current, template) => current.Replace(match.Value, template.Value)));
image.Font = conf.Font;
image.FontPointsize = conf.FontSize;
Color color = (Color) ColorConverter.ConvertFromString(conf.FontColor);
image.FillColor = new MagickColor(color.R, color.G, color.B, color.A);
image.StrokeColor = new MagickColor(color.R, color.G, color.B, color.A);
image.Annotate(text, gravity);
}
image.Format = MagickFormat.Jpeg;
image.Write(dest);
}
return dest;
}