本文整理汇总了C#中System.Windows.Shapes.Rectangle.Arrange方法的典型用法代码示例。如果您正苦于以下问题:C# Rectangle.Arrange方法的具体用法?C# Rectangle.Arrange怎么用?C# Rectangle.Arrange使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类System.Windows.Shapes.Rectangle
的用法示例。
在下文中一共展示了Rectangle.Arrange方法的10个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: CreateScreenshot
/// <summary>Creates the screenshot of entire plotter element</summary>
/// <returns></returns>
internal static BitmapSource CreateScreenshot(UIElement uiElement, Int32Rect screenshotSource)
{
Window window = Window.GetWindow(uiElement);
if (window == null)
{
return CreateElementScreenshot(uiElement);
}
Size size = window.RenderSize;
//double dpiCoeff = 32 / SystemParameters.CursorWidth;
//int dpi = (int)(dpiCoeff * 96);
double dpiCoeff = 1;
int dpi = 96;
RenderTargetBitmap bmp = new RenderTargetBitmap(
(int)(size.Width * dpiCoeff), (int)(size.Height * dpiCoeff),
dpi, dpi, PixelFormats.Default);
// white background
Rectangle whiteRect = new Rectangle { Width = size.Width, Height = size.Height, Fill = Brushes.White };
whiteRect.Measure(size);
whiteRect.Arrange(new Rect(size));
bmp.Render(whiteRect);
// the very element
bmp.Render(uiElement);
CroppedBitmap croppedBmp = new CroppedBitmap(bmp, screenshotSource);
return croppedBmp;
}
示例2: SaveToFile
private void SaveToFile(Viewport3D v, int width, int height)
{
if (Directory.Exists(Path.GetDirectoryName(Assembly.GetEntryAssembly().Location) + "\\renderedData") == false)
{ Directory.CreateDirectory(Path.GetDirectoryName(Assembly.GetEntryAssembly().Location) + "\\renderedData"); }
string destination = Path.GetDirectoryName(Assembly.GetEntryAssembly().Location) + "\\renderedData\\" + DateTime.Now.Year + DateTime.Now.Month + DateTime.Now.Day + " " +
DateTime.Now.Hour + "-" + DateTime.Now.Minute + "-" + DateTime.Now.Second + " " + Environment.UserName + " 3dView.png";
Rectangle vRect = new Rectangle { Width = width, Height = height, Fill = Brushes.White };
vRect.Arrange(new Rect(0, 0, vRect.Width, vRect.Height));
var bmp = new RenderTargetBitmap(width, height, 96, 96, PixelFormats.Pbgra32);
bmp.Render(vRect);
bmp.Render(v);
var png = new PngBitmapEncoder();
png.Frames.Add(BitmapFrame.Create(bmp));
using (var stm = File.Create(destination)) { png.Save(stm); }
}
示例3: Apply
static void Apply(Shader shader, BitmapImage bitmap, string destImage)
{
Rectangle r = new Rectangle ();
r.Effect = shader;
shader.Input = new ImageBrush (bitmap);
/*The fill brush is ignored due to the effect been applied*/
r.Fill = new SolidColorBrush (Colors.Aquamarine);
Size size = new Size (bitmap.PixelWidth, bitmap.PixelHeight);
r.Measure (size);
r.Arrange (new Rect (size));
RenderTargetBitmap render = new RenderTargetBitmap (
bitmap.PixelWidth,
bitmap.PixelHeight,
96,
96,
PixelFormats.Pbgra32);
render.Render (r);
PngBitmapEncoder png = new PngBitmapEncoder ();
png.Frames.Add (BitmapFrame.Create (render));
using (Stream stm = File.Open (destImage, FileMode.OpenOrCreate)) {
png.Save (stm);
}
}
示例4: RenderBitmap
/// <summary>
/// Renders the viewport to a bitmap.
/// </summary>
/// <param name="view">The viewport.</param>
/// <param name="background">The background.</param>
/// <param name="m">The oversampling multiplier.</param>
/// <returns>A bitmap.</returns>
public static BitmapSource RenderBitmap(this Viewport3DX view, Brush background, int m = 1)
{
var target = new WriteableBitmap(
(int)view.ActualWidth * m, (int)view.ActualHeight * m, 96, 96, PixelFormats.Pbgra32, null);
var originalCamera = view.Camera;
var vm = originalCamera.GetViewMatrix3D();
double ar = view.ActualWidth / view.ActualHeight;
for (int i = 0; i < m; i++)
{
for (int j = 0; j < m; j++)
{
// change the camera viewport and scaling
var pm = originalCamera.GetProjectionMatrix3D(ar);
if (originalCamera is OrthographicCamera)
{
pm.OffsetX = m - 1 - (i * 2);
pm.OffsetY = -(m - 1 - (j * 2));
}
if (originalCamera is PerspectiveCamera)
{
pm.M31 = -(m - 1 - (i * 2));
pm.M32 = m - 1 - (j * 2);
}
pm.M11 *= m;
pm.M22 *= m;
var mc = new MatrixCamera(vm, pm);
view.Camera = mc;
var partialBitmap = new RenderTargetBitmap(
(int)view.ActualWidth, (int)view.ActualHeight, 96, 96, PixelFormats.Pbgra32);
// render background
var backgroundRectangle = new Rectangle
{
Width = partialBitmap.Width,
Height = partialBitmap.Height,
Fill = background
};
backgroundRectangle.Arrange(new Rect(0, 0, backgroundRectangle.Width, backgroundRectangle.Height));
partialBitmap.Render(backgroundRectangle);
// render 3d
partialBitmap.Render(view);
// copy to the target bitmap
CopyBitmap(partialBitmap, target, (int)(i * view.ActualWidth), (int)(j * view.ActualHeight));
}
}
// restore the camera
view.Camera = originalCamera;
return target;
}
示例5: CreateHeatMap
protected override void CreateHeatMap()
{
intensityMap = new RenderTargetBitmap(500, 500, 96, 96, PixelFormats.Pbgra32);
AddativeBlendClear cleareffect = new AddativeBlendClear();
cleareffect.ClearColor = Color.FromArgb(0x01, 0xFF, 0xFF, 0xFF);
ClearIntensityMap();
Size sz = new Size(intensityMap.PixelWidth, intensityMap.PixelHeight);
// Create the clear rectangle, we need this to render a fade pass.
clearRectangle = new Rectangle();
clearRectangle.Fill = new ImageBrush(intensityMap);
clearRectangle.Effect = cleareffect;
clearRectangle.Measure(sz);
clearRectangle.Arrange(new Rect(sz));
// Connect the intensity map containing our heat to our image.
HeatMapImage.Source = intensityMap;
}
示例6: CreateScreenShot
// CreateScreenShot should handle the situation when the FlowDirection of Designer's
// parent is RightToLeft
//
// The structure:
// Root
// |--DesignerView
// The DesignerView is what we're trying to capture.
//
// If Root.FlowDirection is RightToLeft, the DesignerView's capture is a flipped image.
// Say, if DesignerView is diplayed on screen:
// -->==>
// the captured image would be:
// <==<--
// It is Root who flips the image before diplaying on screen.
// But, in our capture, Root will not do the flipping work for us, so we flip the image
// before return.
BitmapSource CreateScreenShot()
{
const double DPI = 96.0;
Rect bounds = VisualTreeHelper.GetDescendantBounds(this.designerPresenter);
int imageWidth = (int)Math.Ceiling(bounds.Right);
int imageHeight = (int)Math.Ceiling(bounds.Bottom);
Rectangle background = new Rectangle()
{
// WindowBrush:
// Gets a SolidColorBrush that is the background
// color in the client area of a window.
Fill = new SolidColorBrush(WorkflowDesignerColors.DesignerViewBackgroundColor),
Width = imageWidth,
Height = imageHeight,
};
background.Arrange(new Rect(0, 0, imageWidth, imageHeight));
RenderTargetBitmap renderBitmap = new RenderTargetBitmap(imageWidth, imageHeight, DPI, DPI, PixelFormats.Pbgra32);
renderBitmap.Render(background);
renderBitmap.Render(this.designerPresenter);
BitmapSource source = BitmapFrame.Create(renderBitmap);
if (IsRightToLeft(this.designerPresenter))
{
return new TransformedBitmap(source, new ScaleTransform(-1, 1, imageWidth / 2, 0));
}
return source;
}
示例7: CreateElementScreenshot
private static BitmapSource CreateElementScreenshot(UIElement uiElement)
{
bool measureValid = uiElement.IsMeasureValid;
if (!measureValid)
{
double width = 300;
double height = 300;
FrameworkElement frElement = uiElement as FrameworkElement;
if (frElement != null)
{
if (!Double.IsNaN(frElement.Width))
width = frElement.Width;
if (!Double.IsNaN(frElement.Height))
height = frElement.Height;
}
Size size = new Size(width, height);
uiElement.Measure(size);
uiElement.Arrange(new Rect(size));
}
RenderTargetBitmap bmp = new RenderTargetBitmap(
(int)uiElement.RenderSize.Width, (int)uiElement.RenderSize.Height,
96, 96, PixelFormats.Default);
// this is waiting for dispatcher to perform measure, arrange and render passes
uiElement.Dispatcher.Invoke(((Action)(() => { })), DispatcherPriority.Background);
Size elementSize = uiElement.DesiredSize;
// white background
Rectangle whiteRect = new Rectangle { Width = elementSize.Width, Height = elementSize.Height, Fill = Brushes.White };
whiteRect.Measure(elementSize);
whiteRect.Arrange(new Rect(elementSize));
bmp.Render(whiteRect);
bmp.Render(uiElement);
return bmp;
}
示例8: LoadImage
private Stream LoadImage(string srcFileName)
{
imgSrc = srcFileName;
imageSource = new BitmapImage(new Uri(srcFileName,UriKind.RelativeOrAbsolute));
columns = (int)Math.Ceiling(imageSource.PixelWidth / 100.0);
rows = (int)Math.Ceiling(imageSource.PixelHeight / 100.0);
var bi = new BitmapImage(new Uri(srcFileName,UriKind.RelativeOrAbsolute));
var imgBrush = new ImageBrush(bi);
imgBrush.AlignmentX = AlignmentX.Left;
imgBrush.AlignmentY = AlignmentY.Top;
imgBrush.Stretch = Stretch.UniformToFill;
RenderTargetBitmap rtb = new RenderTargetBitmap((columns + 1) * 100, (rows + 1) * 100, bi.DpiX, bi.DpiY, PixelFormats.Pbgra32);
var rectBlank = new System.Windows.Shapes.Rectangle();
rectBlank.Width = columns * 100;
rectBlank.Height = rows * 100;
rectBlank.HorizontalAlignment = HorizontalAlignment.Left;
rectBlank.VerticalAlignment = VerticalAlignment.Top;
rectBlank.Fill = new SolidColorBrush(Colors.White);
rectBlank.Arrange(new Rect(0, 0, columns * 100, rows * 100));
var rectImage = new System.Windows.Shapes.Rectangle();
rectImage.Width = imageSource.PixelWidth;
rectImage.Height = imageSource.PixelHeight;
rectImage.HorizontalAlignment = HorizontalAlignment.Left;
rectImage.VerticalAlignment = VerticalAlignment.Top;
rectImage.Fill = imgBrush;
rectImage.Arrange(new Rect((columns * 100 - imageSource.PixelWidth) / 2, (rows * 100 - imageSource.PixelHeight) / 2, imageSource.PixelWidth, imageSource.PixelHeight));
rectImage.Margin = new Thickness(
(columns * 100 - imageSource.PixelWidth) / 2,
(rows * 100 - imageSource.PixelHeight) / 2,
(rows * 100 - imageSource.PixelHeight) / 2,
(columns * 100 - imageSource.PixelWidth) / 2);
rtb.Render(rectBlank);
rtb.Render(rectImage);
png = new PngBitmapEncoder();
png.Frames.Add(BitmapFrame.Create(rtb));
Stream ret = new MemoryStream();
png.Save(ret);
return ret;
}
示例9: SquaredArrow
public SquaredArrow()
{
Rectangle r = new Rectangle();
r.Measure(new Size(100, 100));
r.Arrange(new Rect(0, 0, 100, 100));
}
示例10: LoadImage
//Load image stream
private Stream LoadImage(string srcFileName)
{
this._columns = (int)Math.Ceiling((double)(((double)this.SupportedImageHeight) / this.PieceSize));
this._rows = (int)Math.Ceiling((double)(((double)this.SupportedImageHeight) / this.PieceSize));
var bi = new BitmapImage(new Uri(srcFileName));
var imgBrush = new ImageBrush(bi)
{
AlignmentX = AlignmentX.Left,
AlignmentY = AlignmentY.Top,
Stretch = Stretch.UniformToFill
};
var rectBlank = new Rectangle
{
Width = this._columns * this.PieceSize,
Height = this._rows * this.PieceSize,
HorizontalAlignment = HorizontalAlignment.Left,
VerticalAlignment = VerticalAlignment.Top,
Fill = new SolidColorBrush(Colors.White)
};
rectBlank.Arrange(new Rect(0.0, 0.0, this._columns * this.PieceSize, this._rows * this.PieceSize));
var rectImage = new Rectangle
{
Width = this.SupportedImageWidth,
Height = this.SupportedImageHeight,
HorizontalAlignment = HorizontalAlignment.Left,
VerticalAlignment = VerticalAlignment.Top,
Fill = imgBrush
};
rectImage.Arrange(new Rect(((this._columns * this.PieceSize) - this.SupportedImageWidth) / 2.0,
((this._rows * this.PieceSize) - this.SupportedImageHeight) / 2.0,
(double)this.SupportedImageWidth, (double)this.SupportedImageHeight));
rectImage.Margin = new Thickness(((this._columns * this.PieceSize) - this.SupportedImageWidth) / 2.0,
((this._rows * this.PieceSize) - this.SupportedImageHeight) / 2.0,
((this._rows * this.PieceSize) - this.SupportedImageHeight) / 2.0,
((this._columns * this.PieceSize) - this.SupportedImageWidth) / 2.0);
var rtb = new RenderTargetBitmap((this._columns + 1) * ((int)this.PieceSize),
(this._rows + 1) * ((int)this.PieceSize), bi.DpiX, bi.DpiY,
PixelFormats.Pbgra32);
rtb.Render(rectBlank);
rtb.Render(rectImage);
var png = new PngBitmapEncoder
{
Frames = { BitmapFrame.Create(rtb) }
};
Stream ret = new MemoryStream();
png.Save(ret);
return ret;
}