本文整理汇总了C#中System.Drawing.Drawing2D.GraphicsPath.GetBounds方法的典型用法代码示例。如果您正苦于以下问题:C# GraphicsPath.GetBounds方法的具体用法?C# GraphicsPath.GetBounds怎么用?C# GraphicsPath.GetBounds使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类System.Drawing.Drawing2D.GraphicsPath
的用法示例。
在下文中一共展示了GraphicsPath.GetBounds方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: RotateImg
public Bitmap RotateImg(Bitmap bmp, float angle)
{
var bkColor = Color.White;
int w = bmp.Width;
int h = bmp.Height;
PixelFormat pf;
pf = bkColor == Color.Transparent ? PixelFormat.Format32bppArgb : bmp.PixelFormat;
Bitmap tempImg = new Bitmap(w, h, pf);
Graphics g = Graphics.FromImage(tempImg);
g.Clear(bkColor);
g.DrawImageUnscaled(bmp, 1, 1);
g.Dispose();
GraphicsPath path = new GraphicsPath();
path.AddRectangle(new RectangleF(0f, 0f, w, h));
Matrix mtrx = new Matrix();
//Using System.Drawing.Drawing2D.Matrix class
mtrx.Rotate(angle);
RectangleF rct = path.GetBounds(mtrx);
Bitmap newImg = new Bitmap(Convert.ToInt32(rct.Width), Convert.ToInt32(rct.Height), pf);
g = Graphics.FromImage(newImg);
g.Clear(bkColor);
g.TranslateTransform(-rct.X, -rct.Y);
g.RotateTransform(angle);
g.InterpolationMode = InterpolationMode.HighQualityBilinear;
g.DrawImageUnscaled(tempImg, 0, 0);
g.Dispose();
tempImg.Dispose();
return newImg;
}
示例2: GetRegionImage
public static Image GetRegionImage(Image surfaceImage, GraphicsPath regionFillPath, GraphicsPath regionDrawPath, SurfaceOptions options)
{
if (regionFillPath != null)
{
Image img;
Rectangle regionArea = Rectangle.Round(regionFillPath.GetBounds());
Rectangle screenRectangle = CaptureHelpers.GetScreenBounds0Based();
Rectangle newRegionArea = Rectangle.Intersect(regionArea, screenRectangle);
using (GraphicsPath gp = (GraphicsPath)regionFillPath.Clone())
{
MoveGraphicsPath(gp, -Math.Max(0, regionArea.X), -Math.Max(0, regionArea.Y));
img = ImageHelpers.CropImage(surfaceImage, newRegionArea, gp);
if (options.DrawBorder)
{
GraphicsPath gpOutline = regionDrawPath ?? regionFillPath;
using (GraphicsPath gp2 = (GraphicsPath)gpOutline.Clone())
{
MoveGraphicsPath(gp2, -Math.Max(0, regionArea.X), -Math.Max(0, regionArea.Y));
img = ImageHelpers.DrawOutline(img, gp2);
}
}
}
return img;
}
return null;
}
示例3: OutlinedStringSurface
public OutlinedStringSurface(
String str, Font font, Brush brush, Pen outlinePen,
StringFormat stringFormat)
{
Contract.Requires(str != null);
Contract.Requires(font != null);
Contract.Requires(brush != null);
Contract.Requires(outlinePen != null);
_brush = brush;
_outlinePen = outlinePen;
// グラフィックスパスの生成
_path = new GraphicsPath();
_path.AddString(
str, font.FontFamily, (int)font.Style, font.Size,
new Point(0, 0), stringFormat);
// サイズを取得する
var rect = _path.GetBounds();
Size = rect.Size.ToSize();
// 描画時にマージンがなくなるように平行移動
var matrix = new Matrix(1, 0, 0, 1, -rect.Left, -rect.Top);
_path.Transform(matrix);
// 描画位置を(0, 0)で記憶
matrix.Reset();
_matrix = matrix;
}
示例4: Initialize
void Initialize(GraphicsPath path, WrapMode wrapMode, bool initColors, bool calcCenter) {
_texturePath = path;
_wrapMode = wrapMode;
_rectangle = path.GetBounds();
if (initColors) {
_centerColor = Color.Black;
_surroundColors = new Color []{ Color.White };
}
Bitmap texture = new Bitmap( (int)_rectangle.Width, (int)_rectangle.Height );
Graphics g = Graphics.FromImage( texture );
PointF [] pathPoints = path.PathPoints;
if (calcCenter) {
for (int i=0; i < pathPoints.Length; i++) {
_center.X += pathPoints[i].X;
_center.Y += pathPoints[i].Y;
}
_center.X /= pathPoints.Length;
_center.Y /= pathPoints.Length;
}
int outerColor = 0;
DrawSector( g, CenterPoint, pathPoints[pathPoints.Length-1], pathPoints[0], CenterColor, SurroundColors[outerColor] );
for(int i=0; i < pathPoints.Length - 1; i++) {
if (outerColor < SurroundColors.Length - 1)
outerColor++;
DrawSector( g, CenterPoint, pathPoints[i], pathPoints[i+1], CenterColor, SurroundColors[outerColor] );
}
_nativeObject = new TextureBrush( texture );
}
示例5: ApplyRegionPathToImage
public static Image ApplyRegionPathToImage(Image backgroundImage, GraphicsPath regionFillPath, RegionCaptureOptions options)
{
if (backgroundImage != null && regionFillPath != null)
{
Image img;
Rectangle regionArea = Rectangle.Round(regionFillPath.GetBounds());
Rectangle screenRectangle = CaptureHelpers.GetScreenBounds0Based();
Rectangle newRegionArea = Rectangle.Intersect(regionArea, screenRectangle);
using (GraphicsPath gp = (GraphicsPath)regionFillPath.Clone())
{
using (Matrix matrix = new Matrix())
{
gp.CloseFigure();
matrix.Translate(-Math.Max(0, regionArea.X), -Math.Max(0, regionArea.Y));
gp.Transform(matrix);
}
img = ImageHelpers.CropImage(backgroundImage, newRegionArea, gp);
}
return img;
}
return null;
}
示例6: KiRotate
public static Bitmap KiRotate(Bitmap bmp, float angle, Color bkColor)
{
PixelFormat pf;
int w = bmp.Width + 2;
int h = bmp.Height + 2;
if (bkColor == Color.Transparent)
{
pf = PixelFormat.Format32bppArgb;
}
else
{
pf = bmp.PixelFormat;
}
Bitmap tmp = new Bitmap(w, h, pf);
Graphics g = Graphics.FromImage(tmp);
g.Clear(bkColor);
g.DrawImageUnscaled(bmp, 1, 1);
g.Dispose();
GraphicsPath path = new GraphicsPath();
path.AddRectangle(new RectangleF(0f, 0f, (float)w, (float)h));
Matrix mtrx = new Matrix();
mtrx.Rotate(angle);
RectangleF rct = path.GetBounds(mtrx);
Bitmap dst = new Bitmap((int)rct.Width, (int)rct.Height, pf);
g = Graphics.FromImage(dst);
g.Clear(bkColor);
g.TranslateTransform(-rct.X, -rct.Y);
g.RotateTransform(angle);
g.InterpolationMode = InterpolationMode.HighQualityBilinear;
g.DrawImageUnscaled(tmp, 0, 0);
g.Dispose();
tmp.Dispose();
return dst;
}
示例7: ReturnBounds
public override RectangleF ReturnBounds()
{
GraphicsPath path = new GraphicsPath();
path.AddBezier(pointOne, pointTwo, pointTree, pointFour);
path.Transform(this.TMatrix.TransformationMatrix);
return path.GetBounds();
}
示例8: ReturnBounds
public override RectangleF ReturnBounds()
{
GraphicsPath path = new GraphicsPath();
path.AddEllipse(Location.X, Location.Y, 5, 5);
path.Transform(this.TMatrix.TransformationMatrix);
return path.GetBounds();
}
示例9: ReturnBounds
public override RectangleF ReturnBounds()
{
GraphicsPath path = new GraphicsPath();
path.AddRectangle(new RectangleF(Location.X, Location.Y, ModelSize.Width, ModelSize.Width));
path.Transform(this.TMatrix.TransformationMatrix);
return path.GetBounds();
}
示例10: Form2_Paint
private void Form2_Paint(object sender, PaintEventArgs e)
{
//패스 그래디언트
Point[] pts = { new Point(100, 0), new Point(0, 100), new Point(200, 100) };
PathGradientBrush B = new PathGradientBrush(pts, WrapMode.Tile);
e.Graphics.FillRectangle(B, ClientRectangle);
//패스 그래디언트 끝
//패스변형
GraphicsPath Path = new GraphicsPath();
Path.AddString("한글", new FontFamily("궁서"), 0, 100, new Point(10, 30), new StringFormat());
//확장 후 외곽선 그리기
Path.Widen(new Pen(Color.Black, 3));
e.Graphics.DrawPath(Pens.Black, Path);
//확장 후 채우기
Path.Widen(new Pen(Color.Blue, 3));
e.Graphics.DrawPath(Pens.Black, Path);
//곡선 펴기
Path.Flatten(new Matrix(), 12f);
e.Graphics.DrawPath(Pens.Black, Path);
//회전
Matrix M = new Matrix();
M.Rotate(-10);
Path.Transform(M);
e.Graphics.FillPath(Brushes.Blue, Path);
//휘기
RectangleF R = Path.GetBounds();
PointF[] arPoint = new PointF[4];
arPoint[0] = new PointF(R.Left, R.Top + 30);
arPoint[1] = new PointF(R.Right, R.Top - 10);
arPoint[2] = new PointF(R.Left + 10, R.Bottom - 10);
arPoint[3] = new PointF(R.Right + 30, R.Bottom + 30);
Path.Warp(arPoint, R);
e.Graphics.FillPath(Brushes.Blue, Path);
//클리핑
//graphicspath path= new graphicspath();
//path.fillmode = fillmode.winding;
//path.addellipse(50, 10, 100, 80);
//path.addellipse(20, 45, 160, 120);
//e.graphics.fillpath(brushes.white, path);
//e.graphics.setclip(path);
//for (int y = 0; y < bottom; y+= 20)
//{
// string str = "눈사람의 모양의클리핑 영역에 글자를 쓴것입니다";
// e.graphics.drawstring(str, font, brushes.blue, 0, y);
//}
//클리핑 끝
}
示例11: ReturnBounds
public override RectangleF ReturnBounds()
{
Point[] points = (Point[])pointsList.ToArray(typeof(Point));
GraphicsPath path = new GraphicsPath();
path.AddCurve(points,1);
path.Transform(this.TMatrix.TransformationMatrix);
return path.GetBounds();
}
示例12: FillBackground
/// <summary>
/// Fills the specified <paramref name="path"/> either with a gradient background or a solid one.
/// </summary>
/// <param name="g">The <see cref="Graphics"/> object used to draw.</param>
/// <param name="path">The <see cref="GraphicsPath"/> to fill.</param>
/// <param name="colorStart">The start color.</param>
/// <param name="colorEnd">The end color if drawing a gradient background.</param>
/// <param name="mode">The <see cref="LinearGradientMode"/> to use.</param>
/// <exception cref="ArgumentNullException">If <paramref name="path"/> is null.</exception>
public static void FillBackground(
Graphics g,
GraphicsPath path,
Color colorStart,
Color colorEnd,
LinearGradientMode? mode)
{
if (path == null)
{
throw new ArgumentNullException("path", "parameter 'path' cannot be null.");
}
RectangleF rect = path.GetBounds();
if (!CheckParams(g, path.GetBounds()) || colorStart == Color.Empty)
{
return;
}
if (colorEnd == Color.Empty)
{
if (colorStart != Color.Transparent)
{
using (SolidBrush brush = new SolidBrush(colorStart))
{
g.FillPath(brush, path);
}
}
}
else
{
rect.Height += 2;
rect.Y--;
using (LinearGradientBrush brush = new LinearGradientBrush(
rect,
colorStart,
colorEnd,
mode.GetValueOrDefault(LinearGradientMode.Vertical)))
{
g.FillPath(brush, path);
}
}
}
示例13: HitTest
public bool HitTest(Rectangle r)
{
GraphicsPath gp = new GraphicsPath();
Matrix mtx = new Matrix();
gp.AddRectangle(new Rectangle(el.Location.X,
el.Location.Y,
el.Size.Width,
el.Size.Height));
gp.Transform(mtx);
Rectangle retGp = Rectangle.Round(gp.GetBounds());
return r.Contains (retGp);
}
示例14: Draw
public void Draw(KalikoImage image) {
var graphics = image.Graphics;
var graphicsPath = new GraphicsPath();
var stringFormat = new StringFormat {
Alignment = Alignment,
LineAlignment = VerticalAlignment
};
graphics.SmoothingMode = SmoothingMode.AntiAlias;
graphics.PixelOffsetMode = PixelOffsetMode.HighQuality;
if (Font == null) {
Font = image.Font ?? new Font("Arial", 32, FontStyle.Bold, GraphicsUnit.Pixel);
}
if (TargetArea == Rectangle.Empty) {
TargetArea = new Rectangle(0, 0, image.Width, image.Height);
}
if (Point == Point.Empty) {
graphicsPath.AddString(Text, Font.FontFamily, (int)Font.Style, Font.Size, TargetArea, stringFormat);
}
else {
graphicsPath.AddString(Text, Font.FontFamily, (int)Font.Style, Font.Size, Point, stringFormat);
}
if (Rotation != 0) {
var rotationTransform = new Matrix(1, 0, 0, 1, 0, 0);
var bounds = graphicsPath.GetBounds();
rotationTransform.RotateAt(Rotation, new PointF(bounds.X + (bounds.Width / 2f), bounds.Y + (bounds.Height / 2f)));
graphicsPath.Transform(rotationTransform);
}
if (TextShadow != null) {
DrawShadow(graphics, graphicsPath);
}
if (Outline > 0) {
var pen = new Pen(OutlineColor, Outline) {
LineJoin = LineJoin.Round
};
graphics.DrawPath(pen, graphicsPath);
}
if (TextBrush == null) {
TextBrush = new SolidBrush(TextColor);
}
graphics.FillPath(TextBrush, graphicsPath);
}
示例15: Button
public Button(int x, int y, int sx, int sy, string str, short key,int mode)
{
this.rect = new Rectangle(x, y, sx, sy);
this.name = str;
this.key = key;
this.mode = mode;
this.p = new Point();
p.X = sx / 2 + x;
p.Y = sy / 2 + y - 8;
GraphicsPath path = new GraphicsPath();
path.AddString(str, deffont.FontFamily, (int)deffont.Style, deffont.Size,new PointF(0,0), null);
RectangleF r=path.GetBounds();
p.X -= (int)r.Width-4;
}