本文整理汇总了C#中System.Windows.Media.Imaging.RenderTargetBitmap.Freeze方法的典型用法代码示例。如果您正苦于以下问题:C# RenderTargetBitmap.Freeze方法的具体用法?C# RenderTargetBitmap.Freeze怎么用?C# RenderTargetBitmap.Freeze使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类System.Windows.Media.Imaging.RenderTargetBitmap
的用法示例。
在下文中一共展示了RenderTargetBitmap.Freeze方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: CreateBitmap
public void CreateBitmap()
{
int width = 100;
int height = 100;
int dpi = 96;
Tracing.Log(">> CreateBitmap");
var thread = new Thread(new ThreadStart(() =>
{
Tracing.Log(">> CreateBitmap - Thread start; creating drawing visual");
//Dispatcher.Invoke(new Action(() => {
_drawingVisual = new DrawingVisual();
_drawingContext = _drawingVisual.RenderOpen();
//}));
Tracing.Log(">> CreateBitmap - Drawing to context");
_drawingContext.DrawRectangle(new SolidColorBrush(Colors.HotPink), new Pen(), new Rect(0, 0, 50, 50));
_drawingContext.DrawRectangle(new SolidColorBrush(Colors.Blue), new Pen(), new Rect(50, 0, 50, 50));
_drawingContext.DrawRectangle(new SolidColorBrush(Colors.Orange), new Pen(), new Rect(0, 50, 50, 50));
_drawingContext.DrawRectangle(new SolidColorBrush(Colors.DarkRed), new Pen(), new Rect(50, 50, 50, 50));
_drawingContext.Close();
Tracing.Log(">> CreateBitmap - Finished drawing; creating render target bitmap");
_bitmap = new RenderTargetBitmap(width, height, dpi, dpi, PixelFormats.Default);
_bitmap.Render(_drawingVisual);
Tracing.Log(">> CreateBitmap - Finished work");
_bitmap.Freeze();
}));
//thread.IsBackground = true;
thread.SetApartmentState(ApartmentState.STA);
thread.Start();
}
示例2: Execute
public void Execute(object parameter)
{
var window = _shell as Window;
var targetBitmap = new RenderTargetBitmap(175, 150, 96d, 96d, PixelFormats.Default);
targetBitmap.Render(window);
targetBitmap.Freeze();
var thumbnail = targetBitmap.ToBase64String();
_logger.Info(thumbnail);
}
示例3: CaptureSnapshot
/// <summary>Captures a snapshot of the source element as a bitmap image. The snapshot is created based on the specified rendering parameters.</summary>
/// <param name="sourceElement">The source element.</param>
/// <param name="bitmapSize">The bitmap size.</param>
/// <param name="scalingMode">The bitmap scaling mode.</param>
/// <param name="bitmapDpi">The bitmap dpi.</param>
/// <param name="pixelFormat">The bitmap pixel format.</param>
/// <returns>The snapshot of the source element.</returns>
public static BitmapSource CaptureSnapshot(FrameworkElement sourceElement, Size bitmapSize, BitmapScalingMode scalingMode, Vector bitmapDpi, PixelFormat pixelFormat) {
if (sourceElement == null || bitmapSize.IsZero()) return null;
var snapshot = new RenderTargetBitmap((int)bitmapSize.Width, (int)bitmapSize.Height, bitmapDpi.X, bitmapDpi.Y, pixelFormat);
sourceElement.SetValue(RenderOptions.BitmapScalingModeProperty, scalingMode);
snapshot.Render(sourceElement);
sourceElement.ClearValue(RenderOptions.BitmapScalingModeProperty);
snapshot.Freeze();
return snapshot;
}
示例4: RegisterImageSource
private static void RegisterImageSource(LibraryDevice libraryDevice)
{
var frameworkElement = DeviceControl.GetDefaultPicture(libraryDevice);
frameworkElement.SnapsToDevicePixels = false;
frameworkElement.Width = DesignerItem.DefaultPointSize;
frameworkElement.Height = DesignerItem.DefaultPointSize;
frameworkElement.Arrange(new Rect(new Size(frameworkElement.Width, frameworkElement.Height)));
var imageSource = new RenderTargetBitmap(DesignerItem.DefaultPointSize, DesignerItem.DefaultPointSize, EnvironmentParameters.DpiX, EnvironmentParameters.DpiY, PixelFormats.Pbgra32);
imageSource.Render(frameworkElement);
imageSource.Freeze();
_imageSources.Add(libraryDevice == null ? Guid.Empty : libraryDevice.DriverId, imageSource);
}
示例5: DoDrawing
private void DoDrawing()
{
var drawing = new DrawingVisual();
using (var context = drawing.RenderOpen())
{
DrawImageOperations(context, _imageDrawingOperations);
DrawImageOperations(context, _extraImageDrawingOperations);
}
var output = new RenderTargetBitmap((int)_boundingRect.Width, (int)_boundingRect.Height, 96, 96, PixelFormats.Pbgra32);
output.Render(drawing);
output.Freeze();
Output = output;
}
示例6: Render
public static BitmapSource Render(double rating)
{
StarsRenderer sr = new StarsRenderer();
sr.FillStars(rating);
RenderTargetBitmap rtb = new RenderTargetBitmap(249, 32, 0, 0, PixelFormats.Default);
sr.Measure(new Size(249, 32));
sr.Arrange(new Rect(new Size(249, 32)));
rtb.Render(sr);
rtb.Freeze();
return rtb;
}
示例7: generateImages
private void generateImages(List<string> combos, List<BitmapImage> icons, bool saveToDisk)
{
for(int i = 1; i < combos.Count; i++)
{
String combo = combos[i];
int imageWidth = combo.Length * MaxIconWidth;
int imageHeight = MaxIconHeight;
RenderTargetBitmap bitmap = new RenderTargetBitmap(imageWidth, imageHeight, 96, 96, PixelFormats.Pbgra32);
DrawingVisual drawingVisual = new DrawingVisual();
RenderOptions.SetBitmapScalingMode(drawingVisual, BitmapScalingMode.HighQuality);
using (DrawingContext drawingContext = drawingVisual.RenderOpen())
{
for (int j = 0; j < combo.Length; j++)
{
BitmapImage icon = icons[int.Parse(combo[j].ToString())];
int x = j * MaxIconWidth;
int y = 0;
Rect destRect = new Rect(x, y, MaxIconWidth, MaxIconHeight);
drawingContext.DrawImage(icon, destRect);
}
}
RenderOptions.SetBitmapScalingMode(bitmap, BitmapScalingMode.HighQuality);
bitmap.Render(drawingVisual);
bitmap.Freeze();
if (saveToDisk == true)
{
JpegBitmapEncoder encoder = new JpegBitmapEncoder();
encoder.Frames.Add(BitmapFrame.Create(bitmap, null, null, null));
FileStream outputFile = new FileStream("d:\\image" + i + ".jpg", FileMode.Create);
encoder.Save(outputFile);
}
ImageHash.Add(combo, bitmap);
}
}
示例8: RegisterImageSource
private void RegisterImageSource(LibraryDevice libraryDevice)
{
if (libraryDevice == null)
return;
var frameworkElement = DeviceControl.GetDefaultPicture(libraryDevice);
frameworkElement.Width = 100;
frameworkElement.Height = 100;
frameworkElement.Measure(new Size(frameworkElement.Width, frameworkElement.Height));
frameworkElement.Arrange(new Rect(new Size(frameworkElement.Width, frameworkElement.Height)));
var imageSource = new RenderTargetBitmap(100, 100, 96, 96, PixelFormats.Pbgra32);
imageSource.Render(frameworkElement);
//RenderOptions.SetCachingHint(imageSource, CachingHint.Cache);
imageSource.Freeze();
_imageSources.Add(libraryDevice.DriverId, imageSource);
}
示例9: RenderToImageInMemory
public IBasicImage RenderToImageInMemory()
{
float density = 1;
float dpi = 96;
using (var g = System.Drawing.Graphics.FromHwnd(IntPtr.Zero))
{
dpi = g.DpiX;
density = g.DpiX/96f;
}
var bitmap = new RenderTargetBitmap((int)(BoundsWidth * density), (int)(BoundsHeight * density), dpi, dpi, PixelFormats.Default);
bitmap.Render(_drawingVisual);
bitmap.Freeze();
var image = new BasicImage(bitmap);
return image;
}
示例10: AddPinWithLabel
/// <summary>
/// The arrow demo is uses an adaption of Chales Petzold's WPF arrow class
/// http://charlespetzold.com/blog/2007/04/191200.html to be used as custom MapSape
/// </summary>
/// <param name="layer"></param>
public void AddPinWithLabel(ShapeLayer layer)
{
var center = new System.Windows.Point(8.4, 49); // KA
var radius = 1; // radius in degrees of latitude
var rand = new Random();
Func<System.Windows.Point, double, System.Windows.Point> randomCoordinate = (c, r) =>
{
var angle = rand.NextDouble() * 2 * Math.PI;
var distance = r * Math.Sqrt(rand.NextDouble());
return new System.Windows.Point
{
X = c.X + distance * Math.Cos(angle),
Y = c.Y + distance * Math.Sin(angle)
};
};
bool useBitmapCache = true;
var pin = new Pyramid();
pin.Width = pin.Height = 10;
pin.Measure(new Size(pin.Width, pin.Height));
pin.Arrange(new Rect(0, 0, pin.Width, pin.Height));
var bitmap = new RenderTargetBitmap((int)pin.Width, (int)pin.Height, 96, 96, PixelFormats.Pbgra32);
bitmap.Render(pin);
bitmap.Freeze();
for (int i = 0; i < 5000; i++)
{
FrameworkElement symbol = null;
if(useBitmapCache)
symbol = new Image { Source = bitmap };
else
symbol = new Pyramid();
symbol.Width = pin.Height = 10;
ShapeCanvas.SetLocation(symbol, randomCoordinate(center, radius));
symbol.ToolTip = "Hello";
layer.Shapes.Add(symbol);
}
this.Map.SetMapLocation(center, 9);
}
示例11: ParticleSystem
public ParticleSystem(int maxCount, System.Windows.Media.Color color, Uri source)
{
this.maxParticleCount = maxCount;
this.particleList = new List<Particle>();
this.particleModel = new GeometryModel3D();
this.particleModel.Geometry = new MeshGeometry3D();
Image e = new Image();
e.Source = new BitmapImage( source);
// Ellipse e = new Ellipse();
e.Width = 32.0;
e.Height = 32.0;
// RadialGradientBrush b = new RadialGradientBrush();
// b.GradientStops.Add(new GradientStop(System.Windows.Media.Color.FromArgb(0xFF, color.R, color.G, color.B), 0.25));
// b.GradientStops.Add(new GradientStop(System.Windows.Media.Color.FromArgb(0x00, color.R, color.G, color.B), 1.0));
// e.Fill = b;
e.Measure(new System.Windows.Size(32, 32));
e.Arrange(new Rect(0, 0, 32, 32));
System.Windows.Media.Brush brush = null;
#if USE_VISUALBRUSH
brush = new VisualBrush(e);
#else
RenderTargetBitmap renderTarget = new RenderTargetBitmap(32, 32, 96, 96, PixelFormats.Pbgra32);
renderTarget.Render(e);
renderTarget.Freeze();
brush = new ImageBrush(renderTarget);
#endif
DiffuseMaterial material = new DiffuseMaterial(brush);
this.particleModel.Material = material;
this.rand = new Random(brush.GetHashCode());
}
示例12: ToBitmapSource
public static BitmapSource ToBitmapSource(this TextBlock element, bool freeze = true)
{
var target = new RenderTargetBitmap((int)(element.Width), (int)(element.Height), 96, 96, System.Windows.Media.PixelFormats.Pbgra32);
var brush = new System.Windows.Media.VisualBrush(element);
var visual = new System.Windows.Media.DrawingVisual();
var drawingContext = visual.RenderOpen();
drawingContext.DrawRectangle(brush, null, new Rect(new System.Windows.Point(0, 0),
new System.Windows.Point(element.Width, element.Height)));
drawingContext.Close();
target.Render(visual);
if (freeze)
{
target.Freeze();
}
return target;
}
示例13: RenderToBitmapSource
public static BitmapSource RenderToBitmapSource(this UIElement visual, double scale)
{
Matrix m = PresentationSource.FromVisual(visual).CompositionTarget.TransformToDevice;
int renderHeight = (int)(visual.RenderSize.Height * scale);
int renderWidth = (int)(visual.RenderSize.Width * scale);
var renderTarget = new RenderTargetBitmap(renderWidth, renderHeight, 96, 96, PixelFormats.Pbgra32);
var sourceBrush = new VisualBrush(visual);
var drawingVisual = new DrawingVisual();
using (var drawingContext = drawingVisual.RenderOpen())
{
drawingContext.PushTransform(new ScaleTransform(scale, scale));
drawingContext.DrawRectangle(sourceBrush, null, new Rect(new Point(0, 0), new Point(visual.RenderSize.Width, visual.RenderSize.Height)));
}
renderTarget.Render(drawingVisual);
renderTarget.Freeze();
return renderTarget;
}
示例14: ParticleSystem
public ParticleSystem(int maxCount, Color color)
{
MaxParticleCount = maxCount;
_particleList = new List<Particle>();
_particleModel = new GeometryModel3D {Geometry = new MeshGeometry3D()};
var e = new Ellipse
{
Width = 32.0,
Height = 32.0
};
var b = new RadialGradientBrush();
b.GradientStops.Add(new GradientStop(Color.FromArgb(0xFF, color.R, color.G, color.B), 0.25));
b.GradientStops.Add(new GradientStop(Color.FromArgb(0x00, color.R, color.G, color.B), 1.0));
e.Fill = b;
e.Measure(new Size(32, 32));
e.Arrange(new Rect(0, 0, 32, 32));
Brush brush = null;
#if USE_VISUALBRUSH
brush = new VisualBrush(e);
#else
var renderTarget = new RenderTargetBitmap(32, 32, 96, 96, PixelFormats.Pbgra32);
renderTarget.Render(e);
renderTarget.Freeze();
brush = new ImageBrush(renderTarget);
#endif
var material = new DiffuseMaterial(brush);
_particleModel.Material = material;
_rand = new Random(brush.GetHashCode());
}
示例15: RenderToBitmapCore
private void RenderToBitmapCore(TileIndex id)
{
rendering = true;
var visible = GetTileBounds(id);
Debug.WriteLine(String.Format("Visible is {0} for id={1}", visible.ToString(), id.ToString()));
plotter.Visible = visible;
//plotter.InvalidateVisual();
if (!BackgroundRenderer.GetUsesBackgroundRendering(child))
{
// this is done to make all inside plotter to perform measure and arrange procedures
plotter.Dispatcher.Invoke(() => { }, DispatcherPriority.Input);
RenderTargetBitmap bmp = new RenderTargetBitmap((int)tileSize.Width, (int)tileSize.Height, 96, 96, PixelFormats.Pbgra32);
bmp.Render(plotter);
bmp.Freeze();
ReportSuccessAsync(null, bmp, id);
rendering = false;
}
}