本文整理汇总了C#中System.Windows.Media.Drawing类的典型用法代码示例。如果您正苦于以下问题:C# Drawing类的具体用法?C# Drawing怎么用?C# Drawing使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
Drawing类属于System.Windows.Media命名空间,在下文中一共展示了Drawing类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: DiagramDocumentPaginator
/// <summary>
/// Initializes a new instance of the <see cref="DiagramDocumentPaginator"/> class.
/// </summary>
/// <param name="source">The source.</param>
/// <param name="printSize">Size of the print.</param>
internal DiagramDocumentPaginator(DrawingVisual source, Size printSize)
{
this.PageSize = printSize;
this.contentSize = new Size(this.PageSize.Width - (2 * Constants.Margin), this.PageSize.Height - (2 * Constants.Margin));
this.frameRect = new Rect(new Point(Constants.Margin, Constants.Margin), this.contentSize);
this.frameRect.Inflate(1, 1);
this.framePen = new Pen(Brushes.Black, 0.1);
// Transformation to borderless print size
Rect bounds = source.DescendantBounds;
bounds.Union(source.ContentBounds);
Matrix m = new Matrix();
m.Translate(-bounds.Left, -bounds.Top);
double scale = 1; // hardcoded zoom for printing
this.pageCountX = (int)((bounds.Width * scale) / this.contentSize.Width) + 1;
this.pageCountY = (int)((bounds.Height * scale) / this.contentSize.Height) + 1;
m.Scale(scale, scale);
// Center on available pages
m.Translate(((this.pageCountX * this.contentSize.Width) - (bounds.Width * scale)) / 2, ((this.pageCountY * this.contentSize.Height) - (bounds.Height * scale)) / 2);
// Create a new Visual
DrawingVisual v = new DrawingVisual();
using (DrawingContext dc = v.RenderOpen())
{
dc.PushTransform(new MatrixTransform(m));
dc.DrawDrawing(source.Drawing);
foreach (DrawingVisual dv in source.Children)
{
dc.DrawDrawing(dv.Drawing);
}
}
this.diagram = v.Drawing;
}
示例2: XamlDrawingToPngBase64String
/// <summary>
/// Преобразует XAML Drawing/DrawingGroup в png base64 string
/// </summary>
/// <param name="width"></param>
/// <param name="height"></param>
/// <param name="drawing"></param>
/// <returns>Base64 string containing png bitmap</returns>
public static string XamlDrawingToPngBase64String(int width, int height, Drawing drawing) {
var bitmapEncoder = new PngBitmapEncoder();
// The image parameters...
double dpiX = 96;
double dpiY = 96;
// The Visual to use as the source of the RenderTargetBitmap.
var drawingVisual = new DrawingVisual();
using (var drawingContext = drawingVisual.RenderOpen()) {
drawingContext.DrawDrawing(drawing);
}
var bounds = drawingVisual.ContentBounds;
var targetBitmap = new RenderTargetBitmap(
width * 10, height * 10, dpiX, dpiY,
PixelFormats.Pbgra32);
drawingVisual.Transform = new ScaleTransform(width * 10 / bounds.Width, height * 10 / bounds.Height);
targetBitmap.Render(drawingVisual);
// Encoding the RenderBitmapTarget as an image.
bitmapEncoder.Frames.Add(BitmapFrame.Create(targetBitmap));
byte[] values;
using (var str = new MemoryStream()) {
bitmapEncoder.Save(str);
values = str.ToArray();
}
return Convert.ToBase64String(values);
}
示例3: GetPathGeometries
public static IEnumerable<PathGeometry> GetPathGeometries(Drawing drawing)
{
var result = new List<PathGeometry>();
Action<Drawing> HandleDrawing = null;
HandleDrawing = aDrawing =>
{
if (aDrawing is DrawingGroup)
foreach (Drawing d in ((DrawingGroup)aDrawing).Children)
{
HandleDrawing(d);
}
if (aDrawing is GeometryDrawing)
{
var gd = (GeometryDrawing)aDrawing;
Geometry geometry = gd.Geometry;
if (geometry is PathGeometry)
{
result.Add((PathGeometry)geometry);
}
}
};
HandleDrawing(drawing);
return result;
}
示例4: InternalMakeDrawingSerializable
static void InternalMakeDrawingSerializable(Drawing drawing, GeometryValueSerializer gvs) {
var dg = drawing as DrawingGroup;
if (dg != null)
for(var i = 0; i < dg.Children.Count; ++i)
InternalMakeDrawingSerializable(dg.Children[i], gvs);
else {
var gd = drawing as GeometryDrawing;
if (gd != null) {
var sg = gd.Geometry as StreamGeometry;
if (sg != null && !gvs.CanConvertToString(sg, null))
gd.Geometry = PathGeometry.CreateFromGeometry(sg);
}
}
}
示例5: HitTestPoint
/// <summary>
/// Determines whether or not a point exists in a Drawing
/// </summary>
/// <param name="drawing"> Drawing to hit-test</param>
/// <param name="point"> Point to hit-test for </param>
/// <returns>
/// 'true' if the point exists within the drawing, 'false' otherwise
/// </returns>
internal static bool HitTestPoint(Drawing drawing, Point point)
{
if (drawing != null)
{
HitTestDrawingContextWalker ctx = new HitTestWithPointDrawingContextWalker(point);
drawing.WalkCurrentValue(ctx);
return ctx.IsHit;
}
else
{
return false;
}
}
示例6: DrawingToBitmap
public static BitmapSource DrawingToBitmap(Drawing drawing, int size)
{
DrawingVisual drawingVisual = new DrawingVisual();
DrawingContext drawingContext = drawingVisual.RenderOpen();
drawingContext.PushTransform(new ScaleTransform((double)size / 100, (double)size / 100));
drawingContext.DrawDrawing(drawing);
drawingContext.Pop();
drawingContext.Close();
RenderTargetBitmap bmp = new RenderTargetBitmap(size, size, 96, 96, PixelFormats.Default);
bmp.Render(drawingVisual);
bmp.Freeze();
return bmp;
}
示例7: HitTestGeometry
/// <summary>
/// Hit-tests a Drawing against a PathGeometry
/// </summary>
/// <param name="drawing"> The drawing to hit test against </param>
/// <param name="geometry"> The geometry (in local coordinate space) to hit test. </param>
/// <returns>
/// IntersectionDetail that describes the hit result
/// </returns>
internal static IntersectionDetail HitTestGeometry(Drawing drawing, PathGeometry geometry)
{
if (drawing != null)
{
HitTestDrawingContextWalker ctx =
new HitTestWithGeometryDrawingContextWalker(geometry);
drawing.WalkCurrentValue(ctx);
return ctx.IntersectionDetail;
}
else
{
return IntersectionDetail.Empty;
}
}
示例8: DrawingToBitmap
/// <summary>
/// Conerts a drawing into a bitmap object compatible with System.Drawing.
/// </summary>
/// <param name="drawing"></param>
/// <param name="width"></param>
/// <param name="height"></param>
/// <param name="stretch"></param>
/// <returns></returns>
public static System.Drawing.Bitmap DrawingToBitmap(Drawing drawing, int width, int height, Stretch stretch = Stretch.None)
{
var encoder = new PngBitmapEncoder();
var drawingImage = new DrawingImage(drawing);
var image = new Image() { Source = drawingImage };
image.Stretch = stretch;
image.HorizontalAlignment = HorizontalAlignment.Left;
image.VerticalAlignment = VerticalAlignment.Top;
image.Arrange(new Rect(0, 0, width, height));
var bitmap = new RenderTargetBitmap(width, height, 96, 96, PixelFormats.Pbgra32);
bitmap.Render(image);
encoder.Frames.Add(BitmapFrame.Create(bitmap));
var stream = new MemoryStream();
encoder.Save(stream);
return new System.Drawing.Bitmap(stream);
}
示例9: GuessingPanel
/// <summary>
/// Default constructor.
/// </summary>
public GuessingPanel(Drawing.Drawing drawingToGuess)
{
InitializeComponent();
currentDrawing = drawingToGuess;
drawTimer = new System.Windows.Threading.DispatcherTimer();
drawTimer.Tick += new EventHandler(DrawFrame);
drawTimer.Interval = new TimeSpan(0, 0, 0, 0, REFRESH_TIME_DRAW);
timerIsOver = false;
// Hide buttons and everything
ButtonPlayAgain.Visibility = System.Windows.Visibility.Collapsed;
ButtonCheckScore.Visibility = System.Windows.Visibility.Collapsed;
ButtonTryAgain.Visibility = System.Windows.Visibility.Collapsed;
UserAttemptFeedbackRight.Visibility = System.Windows.Visibility.Collapsed;
UserAttemptFeedbackWrong.Visibility = System.Windows.Visibility.Collapsed;
UserAttemptFeedbackTooLate.Visibility = System.Windows.Visibility.Collapsed;
DoDraw();
// No drawing in this phase
canvas.EditingMode = SurfaceInkEditingMode.None;
}
示例10: NormalizeDrawing
static Drawing NormalizeDrawing(Drawing drawing, Point location, Size size, double angle)
{
DrawingGroup dGroup = new DrawingGroup();
using (DrawingContext dc = dGroup.Open())
{
dc.DrawRectangle(Brushes.Transparent, null, new Rect(new Size(100, 100)));
dc.PushTransform(new RotateTransform(angle, 50, 50));
dc.PushTransform(new TranslateTransform(location.X, location.Y));
dc.PushTransform(new ScaleTransform(size.Width / drawing.Bounds.Width, size.Height / drawing.Bounds.Height));
dc.PushTransform(new TranslateTransform(-drawing.Bounds.Left, -drawing.Bounds.Top));
dc.DrawDrawing(drawing);
dc.Pop();
dc.Pop();
dc.Pop();
dc.Pop();
}
return dGroup;
}
示例11: BuzyWait
static BuzyWait()
{
var drawingVisual = new DrawingVisual ();
using (var drawingContext = drawingVisual.RenderOpen())
{
for (var i = 0; i < Spokes; ++i)
{
var t = ((double)i) / Spokes;
drawingContext.PushOpacity (1 - t);
drawingContext.PushTransform (new RotateTransform (360.0 * t));
drawingContext.DrawRoundedRectangle(
Brushes.White,
null,
new Rect(MinRadius, -WidthRadius/2, RadiusRadius - MinRadius, WidthRadius),
WidthRadius,
WidthRadius
);
drawingContext.Pop ();
drawingContext.Pop ();
}
}
s_drawing = drawingVisual.Drawing.FreezeObject ();
s_animationClock = new DoubleAnimation (
0,
1,
new Duration (TimeSpan.FromSeconds(2))
)
{
RepeatBehavior = RepeatBehavior.Forever
};
s_animationClock.FreezeObject ();
}
示例12: GraphPaginator
internal GraphPaginator( DrawingVisual source, Size printSize )
{
PageSize = printSize;
contentSize = new Size( printSize.Width - 2 * Margin, printSize.Height - 2 * Margin );
myFrameRect = new Rect( new Point( Margin, Margin ), contentSize );
myFrameRect.Inflate( 1, 1 );
myFramePen = new Pen( Brushes.Black, 0.1 );
// Transformation to borderless print size
var bounds = source.DescendantBounds;
bounds.Union( source.ContentBounds );
var m = new Matrix();
m.Translate( -bounds.Left, -bounds.Top );
double scale = 16; // hardcoded zoom for printing
myPageCountX = ( int )( ( bounds.Width * scale ) / contentSize.Width ) + 1;
myPageCountY = ( int )( ( bounds.Height * scale ) / contentSize.Height ) + 1;
m.Scale( scale, scale );
// Center on available pages
m.Translate( ( myPageCountX * contentSize.Width - bounds.Width * scale ) / 2, ( myPageCountY * contentSize.Height - bounds.Height * scale ) / 2 );
var target = new DrawingVisual();
using( var dc = target.RenderOpen() )
{
dc.PushTransform( new MatrixTransform( m ) );
dc.DrawDrawing( source.Drawing );
foreach( DrawingVisual child in source.Children )
{
dc.DrawDrawing( child.Drawing );
}
}
myGraph = target.Drawing;
}
示例13: AfterGuessingPanel
public AfterGuessingPanel(Drawing.Drawing drawingGuessed, ulong userScore)
{
this.InitializeComponent();
this.userScore = userScore;
bool isHighscore = false;
IsHighScoreFeedback.Visibility = System.Windows.Visibility.Collapsed;
IsNotHighScoreFeedback.Visibility = System.Windows.Visibility.Collapsed;
SaveFeedbackOK.Visibility = System.Windows.Visibility.Collapsed;
SaveFeedbackNOTOK.Visibility = System.Windows.Visibility.Collapsed;
ButtonGoBackHome.Visibility = System.Windows.Visibility.Collapsed;
currentDrawing = drawingGuessed;
UserScore.Text = FormatScore(userScore);
Highscores.Highscore high = App.client.GetHighscoreFromServer(drawingGuessed);
if (high != null)
{
ChampionScore.Text = FormatScore(high.score);
ChampionIdentity.Text = "By " + high.scorerName + " at " + high.scoreTimestamp;
isHighscore = Highscores.Highscore.CompareScores(userScore, high.score);
}
else
{
ChampionScore.Text = FormatScore(userScore);
ChampionIdentity.Text = "";
ChampionIdentity.Visibility = System.Windows.Visibility.Collapsed;
isHighscore = true;
}
if (isHighscore)
{
IsHighScoreFeedback.Visibility = System.Windows.Visibility.Visible;
IsNotHighScoreFeedback.Visibility = System.Windows.Visibility.Collapsed;
}
else
{
IsHighScoreFeedback.Visibility = System.Windows.Visibility.Collapsed;
IsNotHighScoreFeedback.Visibility = System.Windows.Visibility.Visible;
}
}
示例14: ColorizeDrawing
static void ColorizeDrawing(Drawing drawing, Color tintColor)
{
if (drawing is DrawingGroup)
{
var dg = (DrawingGroup)drawing;
foreach (var d in dg.Children)
{
ColorizeDrawing(d, tintColor);
}
}
else if (drawing is GeometryDrawing)
{
var gd = (GeometryDrawing)drawing;
if (gd.Brush != null)
ColorizeBrush(gd.Brush, tintColor);
if (gd.Pen != null)
ColorizeBrush(gd.Pen.Brush, tintColor);
}
else
{
throw new NotImplementedException();
}
}
示例15: AddDrawing
public void AddDrawing(Drawing drawing)
{
_drawings.Clear();
_drawings.Add(drawing);
}