本文整理匯總了C#中System.Drawing.Bitmap.CropImage方法的典型用法代碼示例。如果您正苦於以下問題:C# Bitmap.CropImage方法的具體用法?C# Bitmap.CropImage怎麽用?C# Bitmap.CropImage使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類System.Drawing.Bitmap
的用法示例。
在下文中一共展示了Bitmap.CropImage方法的4個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的C#代碼示例。
示例1: Run
public static void Run()
{
float fontSize = 36.0f;
//Font font = new Font("Arabic Typesetting", fontSize);
string basePath = @"C:\Users\KESKIN\Desktop\cevsen\out\";
Font font = new Font("Scheherazade", fontSize);
var brush1 = new SolidBrush(Color.FromArgb(85, 0, 0));
var brush2 = new SolidBrush(Color.FromArgb(0, 85, 0));
var cuz = 0;
/*
foreach (var item in Kuran.kuran)
{
var cuzIndex = Kuran.cuzler.IndexOf(s => s == item.Key);
if (cuzIndex > -1) cuz = cuzIndex + 1;
if (!Directory.Exists(basePath + cuz)) Directory.CreateDirectory(basePath + cuz);
using (Bitmap a = new Bitmap(5000, (int)(fontSize + fontSize)))
{
using (Graphics g = Graphics.FromImage(a))
{
for (int i = 0; i < item.Value.Length; i++)
{
if (File.Exists(basePath + cuz + "\\" + item.Key + "_" + i + ".png")) continue;
SizeF size = g.MeasureString(item.Value[i], font);
g.TextRenderingHint = TextRenderingHint.AntiAlias;
g.Clear(Color.Transparent);
g.DrawString(item.Value[i], font, i%2==0?brush1:brush2, new PointF(0, fontSize / 7f)); // requires font, brush etc
Bitmap b = (Bitmap)a.CropImage(0, 0, (int)size.Width, (int)size.Height, false);
b.SavePng(basePath + cuz + "\\" + item.Key + "_" + i + ".png");
}
}
}
Console.WriteLine(item.Key);
//if(ayetNo==10) break;
}
*/
Dictionary<string, string[]> cevsen = CevsenFromFileToCode.Run();
using (Bitmap a = new Bitmap(5000, (int)(fontSize + fontSize)))
{
using (Graphics g = Graphics.FromImage(a))
{
foreach (var item in cevsen) // new Dictionary<string, string[]> { { "subhan_hamd_0", new String[] { "سُبْحاَنَ", "اللَّهِ", "وَ", "الْحَمْدُ", "لِلَّهِ", "وَ", "لَا", "اِلَهَ", "اِلَّا", "اللَّهُ", "وَاللَّهُ", "اَكْبَرُ", "وَ", "لَا", "حَوْلَ", "وَ", "لَا", "قُوَّةَ", "اِلَّا", "بِاللَّهِ", "الْعَلِىِّ", "الْعَظِيمِ", } } }
for (int i = 0; i < item.Value.Length; i++)
{
SizeF size = g.MeasureString(item.Value[i], font);
g.TextRenderingHint = TextRenderingHint.AntiAlias;
g.Clear(Color.Transparent);
g.DrawString(item.Value[i], font, i % 2 == 0 ? brush1 : brush2, new PointF(0, fontSize / 7f)); // requires font, brush etc
Bitmap b = (Bitmap)a.CropImage(0, 0, (int)size.Width, (int)size.Height, false);
b.SavePng(basePath + item.Key + "_" + i + ".png");
}
}
}
}
示例2: TestCropImageToMaximumDimension
public void TestCropImageToMaximumDimension()
{
using (var image = new Bitmap(ImageLocation))
{
var resizedImage = image.CropImage(90);
Assert.AreEqual(90, resizedImage.Width);
resizedImage.Dispose();
}
}
示例3: TestCropImage
public void TestCropImage()
{
using (var image = new Bitmap(ImageLocation))
{
var resizedImage = image.CropImage(320, 200);
Assert.AreEqual(320, resizedImage.Width);
Assert.AreEqual(200, resizedImage.Height);
resizedImage.Dispose();
}
}
示例4: Main
static void Main(string[] args)
{
var paramsControl = new ParamsControl<CommandLineParamsOptions>(new CommandLineParamsOptions(), args, "Thumbnail extractor");
var valid = paramsControl.Validate();
if (valid == false)
{
Console.WriteLine(paramsControl.GenerateError());
return;
}
FileAttributes sourceAttributes = FileAttributes.Normal;
try
{
sourceAttributes = File.GetAttributes(paramsControl.Values.Source);
}
catch(Exception ex)
{
Console.WriteLine("Failed to get the file: " + ex.ToString());
return;
}
IEnumerable<string> videosToProcess = null;
if(sourceAttributes.HasFlag(FileAttributes.Directory))
{
videosToProcess = Directory.GetFiles(paramsControl.Values.Source, "*m.mp4", SearchOption.AllDirectories);
}
else
{
videosToProcess = new string [] { paramsControl.Values.Source };
}
foreach(var videoPath in videosToProcess)
{
string rawOutFile = ExtractFrameToFile(paramsControl, videoPath);
if (File.Exists(rawOutFile))
{
var outFile = GetThumbName(rawOutFile, "play_", ".jpg");
Bitmap raw = new Bitmap(rawOutFile);
raw.CropImage()
.FilterEdge()
//.ToBlackAndWhite()
.Negative()
.Resize(paramsControl.Values.HeightOfTheOutputInPixels)
.AddPlayOverlay()
.Save(outFile);
}
}
Console.WriteLine("Done");
}