本文整理汇总了C#中System.Drawing.Bitmap.GetGraphics方法的典型用法代码示例。如果您正苦于以下问题:C# Bitmap.GetGraphics方法的具体用法?C# Bitmap.GetGraphics怎么用?C# Bitmap.GetGraphics使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类System.Drawing.Bitmap
的用法示例。
在下文中一共展示了Bitmap.GetGraphics方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: CreateGreyscale
public void CreateGreyscale()
{
using (Bitmap b = new Bitmap(100, 100))
{
using (Graphics g = b.GetGraphics())
{
using (LinearGradientBrush brush = new LinearGradientBrush(
new Rectangle(0, 0, 100, 100),
Color.Blue,
Color.Red,
LinearGradientMode.Vertical))
{
brush.SetSigmaBellShape(0.5f);
g.FillRectangle(brush, new Rectangle(0, 0, 100, 100));
using (Bitmap b2 = (Bitmap)b.CreateGreyscale())
{
if (ShowTestForm(b2) != DialogResult.OK)
{
Assert.Fail();
}
}
}
}
}
}
示例2: GetGraphics
public void GetGraphics()
{
using (Bitmap b = new Bitmap(100, 100))
{
using (Graphics g = b.GetGraphics())
{
g.DrawString("Hello World", new Font("Arial", 10), Brushes.Red, new PointF(0, 0));
}
if (ShowTestForm(b) != DialogResult.OK)
{
Assert.Fail();
}
}
}
示例3: GenerateFixationMap
public void GenerateFixationMap(string subject)
{
var path = "maps\\" + subject.Replace(".volke", "");
if (!Directory.Exists("maps")) Directory.CreateDirectory("maps");
if (!Directory.Exists(path)) Directory.CreateDirectory(path);
int idx = 0;
foreach (var fixation in this.GetFixations())
{
var x = (float)fixation.Average(i => i.LeftEye.X);
var y = (float)fixation.Average(i => i.LeftEye.Y);
using (var g = this.BoardImage.GetGraphics())
{
g.Graphics.DrawEllipse(Pens.Red, x, y, 100f, 100f);
g.Graphics.DrawString((++idx).ToString(), new Font("Arial", 12), Brushes.Red, x, y);
}
}
var bmp = new Bitmap(850, 900);
using (var g = bmp.GetGraphics())
{
g.Graphics.DrawString(this.Test.Question, new Font("Calibri", 12), Brushes.Black, 5, 5);
g.Graphics.DrawString(this.Test.IsCorrect ? "SIM" : "NÃO", new Font("Calibri", 12, FontStyle.Bold), Brushes.Black, 5, 22);
g.Graphics.DrawImageUnscaled(this.BoardImage, 0, 80);
}
bmp.Save(path + "\\" + this.Test.Id + ".png");
}
示例4: GenerateHeatMap
public void GenerateHeatMap(string subject)
{
var path = "maps\\" + subject.Replace(".volke", "");
if (!Directory.Exists("maps")) Directory.CreateDirectory("maps");
if (!Directory.Exists(path)) Directory.CreateDirectory(path);
int maskSize = 150;
var mask = GetMask(maskSize);
int[,] exposure = new int[850, 850];
LookPoint.Filters.WeightOOTriangular filter = new LookPoint.Filters.WeightOOTriangular();
int filterCount = 0;
foreach (var eyeTracking in this.GetFixations().SelectMany(i => i))
{
var mx = (eyeTracking.LeftEye.X + eyeTracking.RightEye.X) / 2;
var my = (eyeTracking.LeftEye.Y + eyeTracking.RightEye.Y) / 2;
var fp = filter.feed(++filterCount * 20, new PointF((float)mx, (float)my));
var point = new Point((int)fp.X, (int)fp.Y);
if (point.X < 0 || point.Y < 0 || point.X >= 850 || point.Y >= 850)
continue;
int exposureValue = 10;
for (int x = 0; x < maskSize; x++)
{
int targetX = point.X - (maskSize / 2) + x;
if (targetX < 0 || targetX >= 850) continue;
for (int y = 0; y < maskSize; y++)
{
int targetY = point.Y - (maskSize / 2) + y;
if (targetY < 0 || targetY >= 850 || mask[x, y] == 0) continue;
exposure[targetX, targetY] += exposureValue * mask[x, y];
}
}
}
float max = exposure.Cast<int>().Max();
for (int x = 0; x < 850; x++)
for (int y = 0; y < 850; y++)
this.BoardImage.SetPixel(x, y, GetColor(this.BoardImage.GetPixel(x, y), exposure[x, y], max));
var bmp = new Bitmap(850, 900);
using (var g = bmp.GetGraphics())
{
g.Graphics.DrawString(this.Test.Question, new Font("Calibri", 12), Brushes.Black, 5, 5);
g.Graphics.DrawString(this.Test.IsCorrect ? "SIM" : "NÃO", new Font("Calibri", 12, FontStyle.Bold), Brushes.Black, 5, 22);
g.Graphics.DrawImageUnscaled(this.BoardImage, 0, 80);
}
bmp.Save(path + "\\" + this.Test.Id + ".png");
}