本文整理汇总了C#中System.Windows.Media.DrawingImage.Freeze方法的典型用法代码示例。如果您正苦于以下问题:C# DrawingImage.Freeze方法的具体用法?C# DrawingImage.Freeze怎么用?C# DrawingImage.Freeze使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类System.Windows.Media.DrawingImage
的用法示例。
在下文中一共展示了DrawingImage.Freeze方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: CreateVisuals
/// <summary>
/// Within the given line add the scarlet box behind the a
/// </summary>
private void CreateVisuals(ITextViewLine line)
{
//grab a reference to the lines in the current TextView
IWpfTextViewLineCollection textViewLines = _view.TextViewLines;
int start = line.Start;
int end = line.End;
//Loop through each character, and place a box around any a
for (int i = start; (i < end); ++i)
{
if (_view.TextSnapshot[i] == 'a')
{
SnapshotSpan span = new SnapshotSpan(_view.TextSnapshot, Span.FromBounds(i, i + 1));
Geometry g = textViewLines.GetMarkerGeometry(span);
if (g != null)
{
GeometryDrawing drawing = new GeometryDrawing(_brush, _pen, g);
drawing.Freeze();
DrawingImage drawingImage = new DrawingImage(drawing);
drawingImage.Freeze();
Image image = new Image();
image.Source = drawingImage;
//Align the image with the top of the bounds of the text geometry
Canvas.SetLeft(image, g.Bounds.Left);
Canvas.SetTop(image, g.Bounds.Top);
_layer.AddAdornment(AdornmentPositioningBehavior.TextRelative, span, null, image, null);
}
}
}
}
示例2: CreateAndAddAdornment
void CreateAndAddAdornment(ITextViewLine line, SnapshotSpan span, Brush brush, bool extendToRight)
{
var markerGeometry = _view.TextViewLines.GetMarkerGeometry(span);
double left = markerGeometry.Bounds.Left;
double width = extendToRight ? _view.ViewportWidth + _view.MaxTextRightCoordinate : markerGeometry.Bounds.Width;
Rect rect = new Rect(left, line.Top, width, line.Height);
RectangleGeometry geometry = new RectangleGeometry(rect);
GeometryDrawing drawing = new GeometryDrawing(brush, new Pen(), geometry);
drawing.Freeze();
DrawingImage drawingImage = new DrawingImage(drawing);
drawingImage.Freeze();
Image image = new Image();
image.Source = drawingImage;
Canvas.SetLeft(image, geometry.Bounds.Left);
Canvas.SetTop(image, geometry.Bounds.Top);
_layer.AddAdornment(AdornmentPositioningBehavior.TextRelative, span, null, image, null);
}
示例3: TranslationAdornment
/// <summary>
/// Creates a square image and attaches an event handler to the layout changed event that
/// adds the the square in the upper right-hand corner of the TextView via the adornment layer
/// </summary>
/// <param name="view">The <see cref="IWpfTextView"/> upon which the adornment will be drawn</param>
public TranslationAdornment(IWpfTextView view)
{
_view = view;
Brush brush = new SolidColorBrush(Colors.BlueViolet);
brush.Freeze();
Brush penBrush = new SolidColorBrush(Colors.Red);
penBrush.Freeze();
Pen pen = new Pen(penBrush, 0.5);
pen.Freeze();
//draw a square with the created brush and pen
System.Windows.Rect r = new System.Windows.Rect(0, 0, 30, 30);
Geometry g = new RectangleGeometry(r);
GeometryDrawing drawing = new GeometryDrawing(brush, pen, g);
drawing.Freeze();
DrawingImage drawingImage = new DrawingImage(drawing);
drawingImage.Freeze();
_image = new Image();
_image.Source = drawingImage;
//Grab a reference to the adornment layer that this adornment should be added to
_adornmentLayer = view.GetAdornmentLayer("TranslationAdornment");
_view.ViewportHeightChanged += delegate { this.onSizeChange(); };
_view.ViewportWidthChanged += delegate { this.onSizeChange(); };
}
示例4: AddDecorationError
public void AddDecorationError(BasePropertyDeclarationSyntax _property, string textFull, string toolTipText, FixErrorCallback errorCallback)
{
var lineSpan = tree.GetLineSpan(_property.Span, usePreprocessorDirectives: false);
int lineNumber = lineSpan.StartLinePosition.Line;
var line = _textView.TextSnapshot.GetLineFromLineNumber(lineNumber);
var textViewLine = _textView.GetTextViewLineContainingBufferPosition(line.Start);
int startSpace = textFull.Length - textFull.TrimStart().Length;
int endSpace = textFull.Length - textFull.TrimEnd().Length;
SnapshotSpan span = new SnapshotSpan(_textView.TextSnapshot, Span.FromBounds(line.Start.Position + startSpace, line.End.Position - endSpace));
Geometry g = _textView.TextViewLines.GetMarkerGeometry(span);
if (g != null)
{
rects.Add(g.Bounds);
GeometryDrawing drawing = new GeometryDrawing(_brush, _pen, g);
drawing.Freeze();
DrawingImage drawingImage = new DrawingImage(drawing);
drawingImage.Freeze();
Image image = new Image();
image.Source = drawingImage;
//image.Visibility = Visibility.Hidden;
Canvas.SetLeft(image, g.Bounds.Left);
Canvas.SetTop(image, g.Bounds.Top);
_layer.AddAdornment(AdornmentPositioningBehavior.TextRelative, span, null, image, (t, ui) =>
{
rects.Remove(g.Bounds);
});
DrawIcon(span, g.Bounds.Left - 30, g.Bounds.Top, toolTipText, errorCallback);
}
}
示例5: GetImageSourceFromAxoColor
public static ImageSource GetImageSourceFromAxoColor(AxoColor axoColor, int width, int height)
{
var innerRect = new Rect(0, 0, width, height);
var geometryDrawing = new GeometryDrawing() { Geometry = new RectangleGeometry(innerRect) };
geometryDrawing.Brush = new SolidColorBrush(GuiHelper.ToWpf(axoColor));
DrawingImage geometryImage = new DrawingImage(geometryDrawing);
geometryImage.Freeze(); // Freeze the DrawingImage for performance benefits.
return geometryImage;
}
示例6: Manager
private Manager()
{
#region Creates Loading Threads
_loaderThreadForThumbnails = new Thread(LoaderThreadThumbnails)
{
IsBackground = true,
Priority = ThreadPriority.BelowNormal
};
_loaderThreadForThumbnails.Start();
_loaderThreadForNormalSize = new Thread(LoaderThreadNormalSize)
{
IsBackground = true,
Priority = ThreadPriority.BelowNormal
};
_loaderThreadForNormalSize.Start();
#endregion
Application.Current.Exit += Current_Exit;
#region Loading Images from Resources
var resourceDictionary = new ResourceDictionary
{
Source = new Uri("csCommon;component/Resources/Styles/Resources.xaml", UriKind.Relative)
};
_loadingImage = resourceDictionary["ImageLoading"] as DrawingImage;
_loadingImage.Freeze();
_errorThumbnail = resourceDictionary["ImageError"] as DrawingImage;
_errorThumbnail.Freeze();
#endregion
# region Create Loading Animation
ScaleTransform scaleTransform = new ScaleTransform(0.5, 0.5);
SkewTransform skewTransform = new SkewTransform(0, 0);
RotateTransform rotateTransform = new RotateTransform(0);
TranslateTransform translateTransform = new TranslateTransform(0, 0);
TransformGroup group = new TransformGroup();
group.Children.Add(scaleTransform);
group.Children.Add(skewTransform);
group.Children.Add(rotateTransform);
group.Children.Add(translateTransform);
DoubleAnimation doubleAnimation = new DoubleAnimation(0, 359, new TimeSpan(0, 0, 0, 1));
doubleAnimation.RepeatBehavior = RepeatBehavior.Forever;
rotateTransform.BeginAnimation(RotateTransform.AngleProperty, doubleAnimation);
_loadingAnimationTransform = group;
#endregion
}
示例7: CreateImageToHighlightLine
private Image CreateImageToHighlightLine(Geometry geometry, LineResultMarker marker)
{
GeometryDrawing backgroundGeometry = new GeometryDrawing(marker.Fill, marker.Outline, geometry);
backgroundGeometry.Freeze();
DrawingImage backgroundDrawning = new DrawingImage(backgroundGeometry);
backgroundDrawning.Freeze();
return new Image {Source = backgroundDrawning};
}
示例8: CreateImage
/// <summary>
/// Freezes and then creates an image object from a GeometryGroup.
/// </summary>
/// <param name="brush">The fill brush for the group.</param>
/// <param name="pen">The Border pen for the group.</param>
/// <param name="group">The group to create an image from.</param>
/// <returns>An image object that can be added to the canvas.</returns>
public static Image CreateImage(this GeometryGroup group, Brush brush, Pen pen)
{
group.Freeze();
var drawing = new GeometryDrawing(brush, pen, group);
drawing.Freeze();
var drawingImage = new DrawingImage(drawing);
drawingImage.Freeze();
return new Image { Source = drawingImage };
}
示例9: AddMarker
private void AddMarker(SnapshotSpan span, Geometry markerGeometry, FormatInfo formatInfo)
{
GeometryDrawing drawing = new GeometryDrawing(formatInfo.Background, formatInfo.Outline, markerGeometry);
drawing.Freeze();
DrawingImage drawingImage = new DrawingImage(drawing);
drawingImage.Freeze();
Image image = new Image();
image.Source = drawingImage;
// Align the image with the top of the bounds of the text geometry
Canvas.SetLeft(image, markerGeometry.Bounds.Left);
Canvas.SetTop(image, markerGeometry.Bounds.Top);
adornmentLayer.AddAdornment(AdornmentPositioningBehavior.TextRelative, span, null, image, null);
}
示例10: UpdateDebugInfo
private void UpdateDebugInfo(object sender, EventArgs e)
{
if (m_bWaitThread && Singleton<BusinessLogic>.Instance.ThreadHasFinished())
{
m_bWaitThread = false;
Info.Content = "完成";
m_timer.Stop();
m_timer = null;
// 随便画画
DrawingGroup imageDrawings = new DrawingGroup();
Card[] cards = Singleton<CardRepository>.Instance.Cards;
for (int i = 0; i < cards.Length; ++i)
{
ImageDrawing image = new ImageDrawing();
image.Rect = new Rect(i * 50, 50, 150, 200);
image.ImageSource = new BitmapImage(new Uri(cards[i].ImagePath, UriKind.Relative));
imageDrawings.Children.Add(image);
}
DrawingImage drawingImageSource = new DrawingImage(imageDrawings);
drawingImageSource.Freeze();
Image imageControl = new Image();
imageControl.Stretch = Stretch.None;
imageControl.Source = drawingImageSource;
Border imageBorder = new Border();
imageBorder.BorderBrush = Brushes.Gray;
imageBorder.BorderThickness = new Thickness(1);
imageBorder.HorizontalAlignment = HorizontalAlignment.Left;
imageBorder.VerticalAlignment = VerticalAlignment.Top;
imageBorder.Margin = new Thickness(20);
imageBorder.Child = imageControl;
CardsBrowser.Content = imageBorder;
}
else
{
Info.Content = m_strMsg;
}
}
示例11: GetColorSwatch
public static ImageSource GetColorSwatch(System.Drawing.Color value)
{
Color color = Color.FromArgb(value.A, value.R, value.G, value.B);
GeometryGroup group = new GeometryGroup();
group.Children.Add(new RectangleGeometry(new Rect(new Size(50, 50))));
GeometryDrawing drawing = new GeometryDrawing()
{
Geometry = group,
Brush = new SolidColorBrush(color),
Pen = new Pen(Brushes.Transparent, 10),
};
DrawingImage image = new DrawingImage(drawing);
image.Freeze();
return image;
}
示例12: Manager
private Manager()
{
#region Creates Loading Threads
_loaderThreadForThumbnails = new Thread(new ThreadStart(LoaderThreadThumbnails));
_loaderThreadForThumbnails.IsBackground = true; // otherwise, the app won't quit with the UI...
_loaderThreadForThumbnails.Priority = ThreadPriority.BelowNormal;
_loaderThreadForThumbnails.Start();
_loaderThreadForNormalSize = new Thread(new ThreadStart(LoaderThreadNormalSize));
_loaderThreadForNormalSize.IsBackground = true; // otherwise, the app won't quit with the UI...
_loaderThreadForNormalSize.Priority = ThreadPriority.BelowNormal;
_loaderThreadForNormalSize.Start();
#endregion
#region Loading Images from Resources
ResourceDictionary resourceDictionary = new ResourceDictionary();
resourceDictionary.Source = new Uri("/ByteFlood;component/Controls/PhotoLoader/Resources.xaml", UriKind.Relative);
_loadingImage = resourceDictionary["ImageLoading"] as DrawingImage;
_loadingImage.Freeze();
_errorThumbnail = resourceDictionary["ImageError"] as DrawingImage;
_errorThumbnail.Freeze();
#endregion
# region Create Loading Animation
ScaleTransform scaleTransform = new ScaleTransform(0.5, 0.5);
SkewTransform skewTransform = new SkewTransform(0, 0);
RotateTransform rotateTransform = new RotateTransform(0);
TranslateTransform translateTransform = new TranslateTransform(0, 0);
TransformGroup group = new TransformGroup();
group.Children.Add(scaleTransform);
group.Children.Add(skewTransform);
group.Children.Add(rotateTransform);
group.Children.Add(translateTransform);
DoubleAnimation doubleAnimation = new DoubleAnimation(0, 359, new TimeSpan(0, 0, 0, 1));
doubleAnimation.RepeatBehavior = RepeatBehavior.Forever;
rotateTransform.BeginAnimation(RotateTransform.AngleProperty, doubleAnimation);
_loadingAnimationTransform = group;
#endregion
}
示例13: UpdateRazerDisplay
public void UpdateRazerDisplay(Color[,] colors)
{
// No point updating the display if the view isn't visible
if (!IsActive)
return;
var visual = new DrawingVisual();
using (var dc = visual.RenderOpen())
{
dc.PushClip(new RectangleGeometry(new Rect(0, 0, 22, 6)));
for (var y = 0; y < 6; y++)
{
for (var x = 0; x < 22; x++)
dc.DrawRectangle(new SolidColorBrush(colors[y, x]), null, new Rect(x, y, 1, 1));
}
}
var drawnDisplay = new DrawingImage(visual.Drawing);
drawnDisplay.Freeze();
RazerDisplay = drawnDisplay;
}
示例14: GetImage
//.........这里部分代码省略.........
drawing1.Geometry = new LineGeometry(new Point(0, height / 2), new Point(width, height / 2));
drawing1.Pen = new Pen(Brushes.Black, lineWidth);
group.Children.Add(drawing1);
drawing1 = new GeometryDrawing();
drawing1.Geometry = new LineGeometry(new Point(width / 2, 0), new Point(width / 2, height));
drawing1.Pen = new Pen(Brushes.Black, lineWidth);
group.Children.Add(drawing1);
}
else
{
var drawing1 = new GeometryDrawing();
if (absscale > 2)
drawing1.Geometry = new EllipseGeometry(new Point(width / 2, height / 2), (width / 2), (height / 2) / absscale);
else if (absscale > 1)
drawing1.Geometry = new EllipseGeometry(new Point(width / 2, height / 2), (width / 4) * absscale, (height / 4));
else if (absscale > 0.5)
drawing1.Geometry = new EllipseGeometry(new Point(width / 2, height / 2), (width / 4), (height / 4) / absscale);
else if (absscale > 0)
drawing1.Geometry = new EllipseGeometry(new Point(width / 2, height / 2), (width / 2) * absscale, (height / 2));
// drawing1.Brush = new RadialGradientBrush(Color.FromRgb(204, 204, 255), Color.FromRgb(100, 100, 255));
if (scale > 0)
drawing1.Brush = new LinearGradientBrush(Color.FromRgb(204, 204, 255), Color.FromRgb(100, 100, 255), 0);
else
drawing1.Brush = new LinearGradientBrush(Color.FromRgb(100, 100, 255), Color.FromRgb(204, 204, 255), 0);
group.Children.Add(drawing1);
drawing1 = new GeometryDrawing();
drawing1.Geometry = new LineGeometry(new Point(0, height / 2), new Point(width, height / 2));
drawing1.Pen = new Pen(Brushes.Black, lineWidth);
group.Children.Add(drawing1);
Point d11, d12, d13;
Point d21, d22, d23;
if (absscale > 1)
{
// triangles pointing outside;
d11 = new Point(0, height / 2);
d12 = new Point(width / 4, height / 2 + height / 8);
d13 = new Point(width / 4, height / 2 - height / 8);
d21 = new Point(width, height / 2);
d22 = new Point(width - width / 4, height / 2 + height / 8);
d23 = new Point(width - width / 4, height / 2 - height / 8);
}
else
{
// triangles pointing inside
d11 = new Point(width / 4, height / 2);
d12 = new Point(0, height / 2 + height / 8);
d13 = new Point(0, height / 2 - height / 8);
d21 = new Point(width - width / 4, height / 2);
d22 = new Point(width, height / 2 + height / 8);
d23 = new Point(width, height / 2 - height / 8);
}
// now adjust the triangles a little
if (absscale > 2)
{
// nothing to do here, the triangles are already max outside
}
else if (absscale > 1)
{
double offs = width / 2 - absscale * (width / 4);
d11.X += offs; d12.X += offs; d13.X += offs;
d21.X -= offs; d22.X -= offs; d23.X -= offs;
}
else if (absscale > 0.5)
{
// nothing to do here, the triangles are already max outside
}
else if (absscale > 0)
{
double offs = width / 4 - absscale * width / 2;
d11.X += offs; d12.X += offs; d13.X += offs;
d21.X -= offs; d22.X -= offs; d23.X -= offs;
}
var fig1 = new PathFigure(d11, new PathSegment[] { new LineSegment(d12, false), new LineSegment(d13, false) }, true);
var fig2 = new PathFigure(d21, new PathSegment[] { new LineSegment(d22, false), new LineSegment(d23, false) }, true);
drawing1 = new GeometryDrawing();
drawing1.Geometry = new PathGeometry(new PathFigure[] { fig1, fig2 });
drawing1.Brush = Brushes.Black;
group.Children.Add(drawing1);
}
if (isForY)
group.Transform = new RotateTransform(90, width / 2, height / 2);
var geometryImage = new DrawingImage(group);
// Freeze the DrawingImage for performance benefits.
geometryImage.Freeze();
return geometryImage;
}
示例15: CreateVisuals
private void CreateVisuals(ITextViewLine line)
{
{
var text = line.Extent.GetText();
if (!regex.IsMatch(text)) return;
}
IWpfTextViewLineCollection textViewLines = this.view.TextViewLines;
// Loop through each character, and place a box around any 'a'
for (int charIndex = line.Start; charIndex < line.End; charIndex++)
{
if (this.view.TextSnapshot[charIndex] == 'a')
{
SnapshotSpan span = new SnapshotSpan(this.view.TextSnapshot, Span.FromBounds(charIndex, charIndex + 1));
Geometry geometry = textViewLines.GetMarkerGeometry(span);
if (geometry != null)
{
var drawing = new GeometryDrawing(this.brush, this.pen, geometry);
drawing.Freeze();
var drawingImage = new DrawingImage(drawing);
drawingImage.Freeze();
var image = new Image
{
Source = drawingImage,
};
// Align the image with the top of the bounds of the text geometry
Canvas.SetLeft(image, geometry.Bounds.Left);
Canvas.SetTop(image, geometry.Bounds.Top);
this.layer.AddAdornment(AdornmentPositioningBehavior.TextRelative, span, null, image, null);
}
}
}
}