本文整理汇总了C#中System.Windows.Media.ImageBrush.Freeze方法的典型用法代码示例。如果您正苦于以下问题:C# ImageBrush.Freeze方法的具体用法?C# ImageBrush.Freeze怎么用?C# ImageBrush.Freeze使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类System.Windows.Media.ImageBrush
的用法示例。
在下文中一共展示了ImageBrush.Freeze方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: Create
public Model3DGroup Create(Color modelColor,string pictureName, Point3D startPos, double maxHigh)
{
try
{
Uri inpuri = new Uri(@pictureName, UriKind.Relative);
BitmapImage bi = new BitmapImage();
bi.BeginInit();
bi.UriSource = inpuri;
bi.EndInit();
ImageBrush imagebrush = new ImageBrush(bi);
imagebrush.Opacity = 100;
imagebrush.Freeze();
Point[] ptexture0 = { new Point(0, 0), new Point(0, 1), new Point(1, 0) };
Point[] ptexture1 = { new Point(1, 0), new Point(0, 1), new Point(1, 1) };
SolidColorBrush modelbrush = new SolidColorBrush(modelColor);
Model3DGroup cube = new Model3DGroup();
Point3D uppercircle = startPos;
modelbrush.Freeze();
uppercircle.Y = startPos.Y + maxHigh;
cube.Children.Add(CreateEllipse2D(modelbrush, uppercircle, _EllipseHigh, new Vector3D(0, 1, 0)));
cube.Children.Add(CreateEllipse2D(modelbrush, startPos, _EllipseHigh, new Vector3D(0, -1, 0)));
cube.Children.Add(CreateEllipse3D(imagebrush, startPos, _EllipseHigh, maxHigh, ptexture0));
return cube;
}
catch (Exception ex)
{
throw ex;
}
}
示例2: Airplane
static Airplane()
{
try
{
Assembly assembly = Assembly.GetExecutingAssembly();
string[] names = assembly.GetManifestResourceNames();
string name = names.FirstOrDefault(x => x.Contains("WFTools3D.jpg"));
if (name != null)
{
Stream stream = assembly.GetManifestResourceStream(name);
if (stream != null)
{
BitmapImage bitmap = new BitmapImage();
bitmap.BeginInit();
bitmap.StreamSource = stream;
bitmap.EndInit();
ImageBrush imbrush = new ImageBrush(bitmap);
imbrush.TileMode = TileMode.Tile;
imbrush.Viewport = new Rect(0, 0, 0.5, 1);
imbrush.Freeze();
brush = imbrush;
}
}
}
catch
{
brush = Brushes.Silver;
}
}
示例3: RegisterBrush
private static void RegisterBrush(LibraryDevice libraryDevice)
{
var imageSource = GetImageSource(libraryDevice == null ? Guid.Empty : libraryDevice.DriverId);
var brush = new ImageBrush(imageSource);
brush.Freeze();
_brushes.Add(libraryDevice == null ? Guid.Empty : libraryDevice.DriverId, brush);
}
示例4: CreateBrushFromVisual
/// <summary>
/// Erzeugt einen gerenderten Brush aus einem Visual
/// </summary>
/// <param name="visual"></param>
/// <returns></returns>
public static Brush CreateBrushFromVisual(Visual visual, int width, int height)
{
if (visual == null)
throw new ArgumentNullException("visual");
RenderTargetBitmap target = new RenderTargetBitmap(Math.Max(width, 1), Math.Max(height, 1), 96, 96, PixelFormats.Pbgra32);
target.Render(visual);
ImageBrush brush = new ImageBrush(target);
brush.Freeze();
return brush;
}
示例5: SetEnvironmentImageBrush
private static void SetEnvironmentImageBrush(ResourceDictionary resources, BitmapSource bitmapImage, bool tileImage)
{
TileMode tileMode;
ImageBrush imageBrush = new ImageBrush(bitmapImage);
ImageBrush imageBrush1 = imageBrush;
tileMode = tileImage ? TileMode.Tile : TileMode.None;
imageBrush.TileMode = tileMode;
imageBrush.Viewport = new Rect(0, 0, bitmapImage.Width, bitmapImage.Height);
imageBrush.ViewboxUnits = BrushMappingMode.Absolute;
if(imageBrush.CanFreeze)
imageBrush.Freeze();
//todo: Create a persistentance mechanism
//SaveDefaultEnvironmentBrush(resources);
resources[VsBrushes.EnvironmentBackgroundTextureKey] = imageBrush;
}
示例6: AddNewShapeLight
private void AddNewShapeLight(PatternMaker f)
{
DrawingBrush db = new DrawingBrush();
var dv = new DrawingVisual();
var dc = dv.RenderOpen(); // DrawingContextの取得
Random rd = new Random();
for (int x = 0; x < w; x++)
{
for (int y = 0; y < h; y++)
{
byte alpha = (byte)Math.Floor(f(x, y, w, h, ref rd) * 255);
dc.DrawRectangle(new SolidColorBrush(Color.FromArgb(alpha, 0, 0, 0)), null, new Rect(new Point(x, y), new Point(x + 1, y + 1)));
}
}
dc.Close();
var bitmap = new RenderTargetBitmap(w, h, 96, 96, PixelFormats.Pbgra32);
bitmap.Render(dv); // 描画結果を書き込む
var brush = new ImageBrush(bitmap); // ブラシの作成
brush.ViewportUnits = BrushMappingMode.RelativeToBoundingBox;
brush.Freeze();
Border b = new Border();
b.Background = brush;
b.Width = w;
b.Height = h;
b.BorderBrush = Brushes.DarkGray;
b.BorderThickness = new Thickness(0);
b.Tag = new double[] { 0.0, 1.0 };
b.RenderTransformOrigin = new Point(0.5, 0.5);
RenderOptions.SetBitmapScalingMode(b, BitmapScalingMode.NearestNeighbor);//これを消すと描画モードが変わります。
Random r = new Random();
Canvas.SetLeft(b, r.Next(Math.Max((int)PictureCanvas.ActualWidth - w,0)));
Canvas.SetTop(b, r.Next(Math.Max((int)PictureCanvas.ActualHeight - h,0)));
b.MouseDown += new MouseButtonEventHandler(b_MouseDown);
PictureCanvas.Children.Add(b);
}
示例7: DrawCore
protected override void DrawCore(DrawingContext drawingContext, DrawingAttributes drawingAttributes)
{
if (drawingContext == null)
{
throw new ArgumentNullException("drawingContext");
}
if (null == drawingAttributes)
{
throw new ArgumentNullException("drawingAttributes");
}
DrawingAttributes originalDa = drawingAttributes.Clone();
originalDa.Width = this.size;
originalDa.Height = this.size;
//ImageBrush brush = new ImageBrush(new BitmapImage(new Uri(@"test3.png", UriKind.Relative)));
string path = "pack://application:,,,/Resources/ColorBrush/BColor_" + color + ".png";
ImageBrush brush = new ImageBrush(new BitmapImage(new Uri(path, UriKind.RelativeOrAbsolute)));
brush.Freeze();
drawingContext.DrawGeometry(brush, null, this.GetGeometry(originalDa));
}
示例8: CreateBrushFromVisual
/// <summary>
/// Creates the brush from visual.
/// </summary>
/// <param name="v">The visual object.</param>
/// <param name="width">The width.</param>
/// <param name="height">The height.</param>
/// <returns>The image brush created from the visual</returns>
public static ImageBrush CreateBrushFromVisual(Visual v, double width, double height)
{
try
{
ImageBrush brush = null;
if (height > 0 && width > 0)
{
var target = new RenderTargetBitmap((int)width, (int)height, 96, 96, PixelFormats.Default);
target.Render(v);
brush = new ImageBrush(target);
brush.Stretch = Stretch.None;
brush.Freeze();
}
return brush;
}
catch (Exception ex)
{
MessageBox.Show(ex.Message);
return null;
}
}
示例9: CreateBrushFromVisual
private static Brush CreateBrushFromVisual(Visual v, int width, int height)
{
if (v == null)
throw new ArgumentNullException(nameof(v));
var target = new RenderTargetBitmap(width, height, 96, 96, PixelFormats.Pbgra32);
target.Render(v);
var brush = new ImageBrush(target);
brush.Freeze();
return brush;
}
示例10: CreateBrushFromVisual
/// <summary>
/// Creates a brush based on the current appearnace of a visual element. The brush is an ImageBrush and once created, won't update its look
/// </summary>
/// <param name="v">The visual element to take a snapshot of</param>
private Brush CreateBrushFromVisual(Visual v)
{
if (v == null)
throw new ArgumentNullException("v");
var target = new RenderTargetBitmap((int)this.ActualWidth, (int)this.ActualHeight, 96, 96, PixelFormats.Pbgra32);
target.Render(v);
var brush = new ImageBrush(target);
brush.Freeze();
return brush;
}
示例11: Load
public void Load()
{
try
{
Uri uri = new Uri(ThumnailUrl, UriKind.RelativeOrAbsolute);
WebClient web = new WebClient();
Stream imgData = web.OpenRead(uri);
MemoryStream memory = new MemoryStream();
int data = imgData.ReadByte();
while (data != -1)
{
memory.WriteByte((byte)data);
data = imgData.ReadByte();
}
memory.Seek(0, SeekOrigin.Begin);
BitmapImage bi = new BitmapImage();
//bi.DecodePixelWidth = AppConfig.ThumbSize;
bi.BeginInit();
bi.StreamSource = memory;
bi.EndInit();
bi.Freeze();
brush = new ImageBrush(bi);
brush.Stretch = Stretch.UniformToFill;
brush.Freeze();
}
catch (Exception e)
{
System.Diagnostics.Debug.WriteLine("cannot load image! " + e);
}
}
示例12: Balloon
//.........这里部分代码省略.........
{
if (config.AppSettings.Settings["FontWeight"].Value.Length > 0)
{
this.FontWeight = (FontWeight)new FontWeightConverter().ConvertFromString(config.AppSettings.Settings["FontWeight"].Value);
}
}
if (config.AppSettings.Settings["LineLength"] != null)
{
if (config.AppSettings.Settings["LineLength"].Value.Length > 0)
{
this.baseWidth = Double.Parse(config.AppSettings.Settings["LineLength"].Value, System.Globalization.CultureInfo.InvariantCulture) + 30;
}
}
if (config.AppSettings.Settings["LineHeight"] != null)
{
if (config.AppSettings.Settings["LineHeight"].Value.Length > 0)
{
this.lineHeight = Double.Parse(config.AppSettings.Settings["LineHeight"].Value, System.Globalization.CultureInfo.InvariantCulture);
}
}
if (config.AppSettings.Settings["BackgroundColor"] != null)
{
if (config.AppSettings.Settings["BackgroundColor"].Value.Length > 0)
{
this.backgroundColor = (Color)ColorConverter.ConvertFromString(config.AppSettings.Settings["BackgroundColor"].Value);
}
}
SolidColorBrush brush1 = new SolidColorBrush(Color.FromArgb((byte)(this.backgroundColor.A * 75 / 100), this.backgroundColor.R, this.backgroundColor.G, this.backgroundColor.B));
if (brush1.CanFreeze)
{
brush1.Freeze();
}
this.OuterPath.Fill = brush1;
if (config.AppSettings.Settings["BackgroundImage"] == null)
{
SolidColorBrush brush2 = new SolidColorBrush(this.backgroundColor);
if (brush2.CanFreeze)
{
brush2.Freeze();
}
this.InnerPath.Fill = brush2;
}
else
{
BitmapImage bi = new BitmapImage();
using (FileStream fs = new FileStream(directory == null ? config.AppSettings.Settings["BackgroundImage"].Value : System.IO.Path.Combine(directory, config.AppSettings.Settings["BackgroundImage"].Value), FileMode.Open, FileAccess.Read, FileShare.Read))
{
bi.BeginInit();
bi.StreamSource = fs;
bi.CacheOption = BitmapCacheOption.OnLoad;
bi.CreateOptions = BitmapCreateOptions.None;
bi.EndInit();
}
ImageBrush imageBrush = new ImageBrush(bi);
示例13: OnBackgroundDoWork
private void OnBackgroundDoWork(object sender, DoWorkEventArgs e)
{
PointCloudTileSource tileSource = e.Argument as PointCloudTileSource;
Jacere.Core.Geometry.Extent3D extent = tileSource.Extent;
m_overviewTextureBrush = new ImageBrush(tileSource.Preview.Image);
m_overviewTextureBrush.ViewportUnits = BrushMappingMode.Absolute;
m_overviewTextureBrush.Freeze();
m_overviewMaterial = new DiffuseMaterial(m_overviewTextureBrush);
m_overviewMaterial.Freeze();
if (tileSource != null)
{
previewImageGrid.MouseMove -= OnViewportGridMouseMove;
Action<string> logAction = value => Context.WriteLine(value);
m_progressManager = new BackgroundWorkerProgressManager(m_backgroundWorker, e, logAction, null);
m_gridDimensionLowRes = (ushort)Math.Sqrt(VERTEX_COUNT_FAST / tileSource.TileSet.ValidTileCount);
//m_gridDimensionHighRes = (ushort)Math.Sqrt(VERTEX_COUNT_LARGE / tileSource.TileSet.ValidTileCount);
m_gridDimensionHighRes = (ushort)(Math.Sqrt(tileSource.TileSet.Density.MedianTileCount) / 3);
//m_gridDimensionLowRes = (ushort)20;
//m_gridDimensionHighRes = (ushort)40;
Jacere.Core.Geometry.Point3D centerOfMass = tileSource.CenterOfMass;
m_overallCenteredExtent = new Rect3D(extent.MinX - extent.MidpointX, extent.MinY - extent.MidpointY, extent.MinZ - centerOfMass.Z, extent.RangeX, extent.RangeY, extent.RangeZ);
// load tiles
KeyValuePair<Grid<int>, Grid<float>> gridsLowRes = tileSource.GenerateGrid(m_gridDimensionLowRes);
m_gridLowRes = gridsLowRes.Value;
m_quantizedGridLowRes = gridsLowRes.Key;
KeyValuePair<Grid<int>, Grid<float>> gridsHighRes = tileSource.GenerateGrid(m_gridDimensionHighRes);
m_gridHighRes = gridsHighRes.Value;
m_quantizedGridHighRes = gridsHighRes.Key;
foreach (PointCloudTile tile in tileSource.TileSet)
{
tileSource.LoadTileGrid(tile, m_buffer, m_gridLowRes, m_quantizedGridLowRes);
if (ENABLE_HEIGHT_EXAGGERATION)
m_gridLowRes.Multiply(m_heightExaggerationFactor, (float)centerOfMass.Z);
Jacere.Core.Geometry.Extent3D tileExtent = tile.Extent;
MeshGeometry3D mesh = tileSource.GenerateMesh(m_gridLowRes, tileExtent);
DiffuseMaterial material = new DiffuseMaterial();
if (USE_LOW_RES_TEXTURE)
{
material.Brush = m_overviewTextureBrush;
mesh.TextureCoordinates = MeshUtils.GeneratePlanarTextureCoordinates(mesh, m_overallCenteredExtent, MathUtils.ZAxis);
}
else
{
material.Brush = m_solidBrush;
}
material.Freeze();
GeometryModel3D geometryModel = new GeometryModel3D(mesh, material);
geometryModel.Freeze();
TileInfo3D tileInfo = new TileInfo3D(tile, geometryModel, m_gridLowRes);
m_tileInfo.Add(tile, tileInfo);
// add mappings
m_meshTileMap.Add(geometryModel, tile);
//m_lowResMap.Add(tile, geometryModel);
if (!m_progressManager.Update(tile, geometryModel))
break;
}
//// test
//foreach (double level in new double[] { centerOfMass.Z })
//{
// Grid<float> grid0 = new Grid<float>(20, 20, extent, false);
// grid0.FillVal = (float)level;
// grid0.Reset();
// grid0.FillVal = float.MinValue;
// MeshGeometry3D mesh0 = tileSource.GenerateMesh(grid0, extent);
// DiffuseMaterial material0 = new DiffuseMaterial(m_solidBrush);
// material0.Freeze();
// GeometryModel3D geometryModel0 = new GeometryModel3D(mesh0, material0);
// geometryModel0.Freeze();
// m_progressManager.Update(1.0f, geometryModel0);
//}
if (ENABLE_STITCHING)
{
int validStitchingIndex = 0;
foreach (PointCloudTile tile in tileSource.TileSet)
{
TileInfo3D tileInfo = m_tileInfo[tile];
Model3DGroup stitchingGroup = GenerateTileStitching(tileSource, tileInfo);
if (stitchingGroup != null)
++validStitchingIndex;
//.........这里部分代码省略.........
示例14: BuildTextures
private void BuildTextures(OptFile opt)
{
this.nullTexture = null;
this.textures = null;
if (opt == null)
{
return;
}
this.nullTexture = new DiffuseMaterial(Brushes.White);
this.textures = new Dictionary<string, Material>();
foreach (var texture in opt.Textures.Values)
{
var image = CreateTexture(opt, texture.Name);
image.Freeze();
var brush = new ImageBrush(image)
{
ViewportUnits = BrushMappingMode.Absolute,
Stretch = Stretch.Fill,
TileMode = TileMode.Tile,
Opacity = texture.HasAlpha ? 0.999 : 1.0
};
brush.Freeze();
var material = new DiffuseMaterial(brush);
material.Freeze();
this.textures.Add(texture.Name, material);
}
}
示例15: MakeBrushFromVisual
private Brush MakeBrushFromVisual(Visual visual, Rect bounds)
{
Viewport3D viewport = visual as Viewport3D;
if (viewport == null)
{
Drawing drawing = VisualTreeHelper.GetDrawing(visual);
if (this.drawOutlines)
{
bounds.Inflate(VisualTree3DView.OutlinePen.Thickness / 2, VisualTree3DView.OutlinePen.Thickness / 2);
}
Matrix offsetMatrix = new Matrix(1, 0, 0, 1, -bounds.Left, -bounds.Top);
MatrixTransform offsetMatrixTransform = new MatrixTransform(offsetMatrix);
offsetMatrixTransform.Freeze();
DrawingVisual drawingVisual = new DrawingVisual();
DrawingContext drawingContext = drawingVisual.RenderOpen();
drawingContext.PushTransform(offsetMatrixTransform);
if (this.drawOutlines)
{
drawingContext.DrawRectangle(null, VisualTree3DView.OutlinePen, bounds);
}
drawingContext.DrawDrawing(drawing);
drawingContext.Pop();
drawingContext.Close();
visual = drawingVisual;
}
RenderTargetBitmap renderTargetBitmap = new RenderTargetBitmap((int)Math.Ceiling(bounds.Width), (int)Math.Ceiling(bounds.Height), 96, 96, PixelFormats.Default);
if (viewport != null)
{
typeof(RenderTargetBitmap).GetMethod("RenderForBitmapEffect", System.Reflection.BindingFlags.Instance | System.Reflection.BindingFlags.NonPublic).Invoke(renderTargetBitmap,
new object[] { visual, Matrix.Identity, Rect.Empty });
}
else
{
renderTargetBitmap.Render(visual);
}
renderTargetBitmap.Freeze();
ImageBrush imageBrush = new ImageBrush(renderTargetBitmap);
imageBrush.Freeze();
return imageBrush;
}