本文整理汇总了C#中RenderTarget.CreateLinearGradientBrush方法的典型用法代码示例。如果您正苦于以下问题:C# RenderTarget.CreateLinearGradientBrush方法的具体用法?C# RenderTarget.CreateLinearGradientBrush怎么用?C# RenderTarget.CreateLinearGradientBrush使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类RenderTarget
的用法示例。
在下文中一共展示了RenderTarget.CreateLinearGradientBrush方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: CreateDeviceResources
//.........这里部分代码省略.........
);
IntPtr verticesDataPtr = Marshal.AllocHGlobal(Marshal.SizeOf(VertexArray.VerticesInstance));
Marshal.StructureToPtr(VertexArray.VerticesInstance, verticesDataPtr, true);
BufferDescription bd = new BufferDescription();
bd.Usage = Usage.Default;
bd.ByteWidth = (uint) Marshal.SizeOf(VertexArray.VerticesInstance);
bd.BindFlags = BindFlag.VertexBuffer;
bd.CpuAccessFlags = CpuAccessFlag.Unspecified;
bd.MiscFlags = ResourceMiscFlag.Undefined;
SubresourceData InitData = new SubresourceData()
{
SysMem = verticesDataPtr
};
vertexBuffer = device.CreateBuffer(
bd,
InitData
);
Marshal.FreeHGlobal(verticesDataPtr);
// Set vertex buffer
uint stride = (uint) Marshal.SizeOf(typeof (SimpleVertex));
uint offset = 0;
device.IA.SetVertexBuffers(
0,
new D3DBuffer[] {vertexBuffer},
new uint[] {stride},
new uint[] {offset}
);
IntPtr indicesDataPtr = Marshal.AllocHGlobal(Marshal.SizeOf(VertexArray.IndicesInstance));
Marshal.StructureToPtr(VertexArray.IndicesInstance, indicesDataPtr, true);
bd.Usage = Usage.Default;
bd.ByteWidth = (uint) Marshal.SizeOf(VertexArray.IndicesInstance);
bd.BindFlags = BindFlag.IndexBuffer;
bd.CpuAccessFlags = 0;
bd.MiscFlags = 0;
InitData.SysMem = indicesDataPtr;
facesIndexBuffer = device.CreateBuffer(
bd,
InitData
);
Marshal.FreeHGlobal(indicesDataPtr);
// Set primitive topology
device.IA.SetPrimitiveTopology(PrimitiveTopology.TriangleList);
// Convert the D2D texture into a Shader Resource View
textureResourceView = device.CreateShaderResourceView(
offscreenTexture);
// Initialize the world matrices
worldMatrix = Matrix4x4F.Identity;
// Initialize the view matrix
Vector3F Eye = new Vector3F(0.0f, 0.0f, 13.0f);
Vector3F At = new Vector3F(0.0f, -3.5f, 45.0f);
Vector3F Up = new Vector3F(0.0f, 1.0f, 0.0f);
viewMatrix = Camera.MatrixLookAtLH(Eye, At, Up);
// Initialize the projection matrix
projectionMatrix = Camera.MatrixPerspectiveFovLH(
(float) Math.PI*0.1f,
width/(float) height,
0.1f,
100.0f);
// Update Variables that never change
viewMatrixVariable.Matrix = viewMatrix;
projectionMarixVariable.Matrix = projectionMatrix;
GradientStop[] gradientStops =
{
new GradientStop(0.0f, new ColorF(Colors.Yellow)),
new GradientStop(1.0f, new ColorF(Colors.Black))
};
GradientStopCollection spGradientStopCollection = renderTarget.CreateGradientStopCollection(
gradientStops,
Gamma.Gamma_22,
ExtendMode.Clamp);
// Create a linear gradient brush for text
textBrush = renderTarget.CreateLinearGradientBrush(
new LinearGradientBrushProperties(new Point2F(0, 0), new Point2F(0, -2048)),
spGradientStopCollection
);
}
示例2: CreateD2DRenderTargets
private void CreateD2DRenderTargets()
{
// Create a D2D render target which can draw into our offscreen D3D surface
textureRenderTarget = d2DFactory.CreateGraphicsSurfaceRenderTarget(
textureSurface,
renderTargetProperties
);
// Create a linear gradient brush for the 2D geometry
GradientStopCollection gradientStops = textureRenderTarget.CreateGradientStopCollection(stopsGeometry, Gamma.StandardRgb, ExtendMode.Mirror);
linearGradientBrush = textureRenderTarget.CreateLinearGradientBrush(
new LinearGradientBrushProperties(
new Point2F(100, 0),
new Point2F(100, 200)),
gradientStops
);
// create a black brush
blackBrush = textureRenderTarget.CreateSolidColorBrush(new ColorF(GetColorValues(System.Windows.Media.Colors.Black)));
using (Stream stream = Application.ResourceAssembly.GetManifestResourceStream("Microsoft.WindowsAPICodePack.DirectX.Samples.tulip.jpg"))
{
d2dBitmap = BitmapUtilities.LoadBitmapFromStream(
textureRenderTarget,
imagingFactory,
stream);
}
gridPatternBitmapBrush = CreateGridPatternBrush(textureRenderTarget);
gridPatternBitmapBrush.Opacity = 0.5f;
CreateBackBufferD2DRenderTarget();
}
示例3: CreateBackBufferD2DRenderTarget
private void CreateBackBufferD2DRenderTarget()
{
// Get a surface in the swap chain
using (Surface backBufferSurface = swapChain.GetBuffer<Surface>(0))
{
backBufferRenderTarget = d2DFactory.CreateGraphicsSurfaceRenderTarget(
backBufferSurface,
renderTargetProperties
);
GradientStopCollection stops = backBufferRenderTarget.CreateGradientStopCollection(stopsBackground,
Gamma.StandardRgb,
ExtendMode.Mirror);
backBufferGradientBrush = backBufferRenderTarget.CreateLinearGradientBrush(
new LinearGradientBrushProperties(
new Point2F(0.0f, 0.0f),
new Point2F(0.0f, 1.0f)),
stops);
// Create a red brush for text drawn into the back buffer
backBufferTextBrush = backBufferRenderTarget.CreateSolidColorBrush(new ColorF(GetColorValues(System.Windows.Media.Colors.WhiteSmoke)));
}
}
示例4: CopyBrushToRenderTarget
/// <summary>
/// Creates and returns a copy of the brush in the new render target.
/// Used for changing render targets.
/// A brush belongs to a render target, so when you want to draw with same brush in another render target
/// - you need to create a copy of the brush in the new render target.
/// </summary>
/// <param name="sourceBrush">The brush.</param>
/// <param name="newRenderTarget">The new render target.</param>
/// <returns></returns>
protected internal Brush CopyBrushToRenderTarget(Brush sourceBrush, RenderTarget newRenderTarget)
{
if (sourceBrush == null || newRenderTarget == null)
return null;
Brush newBrush;
if (sourceBrush is SolidColorBrush)
{
newBrush = newRenderTarget.CreateSolidColorBrush(
((SolidColorBrush)sourceBrush).Color,
new BrushProperties(sourceBrush.Opacity, sourceBrush.Transform));
sourceBrush.Dispose();
return newBrush;
}
if (sourceBrush is LinearGradientBrush)
{
var oldGSC = ((LinearGradientBrush)sourceBrush).GradientStops;
var newGSC = newRenderTarget.CreateGradientStopCollection(oldGSC, oldGSC.ColorInterpolationGamma, oldGSC.ExtendMode);
oldGSC.Dispose();
newBrush = newRenderTarget.CreateLinearGradientBrush(
new LinearGradientBrushProperties(
((LinearGradientBrush)sourceBrush).StartPoint,
((LinearGradientBrush)sourceBrush).EndPoint),
newGSC,
new BrushProperties(sourceBrush.Opacity, sourceBrush.Transform));
sourceBrush.Dispose();
return newBrush;
}
if (sourceBrush is RadialGradientBrush)
{
var oldGSC = ((RadialGradientBrush)sourceBrush).GradientStops;
var newGSC = newRenderTarget.CreateGradientStopCollection(oldGSC, oldGSC.ColorInterpolationGamma, oldGSC.ExtendMode);
oldGSC.Dispose();
newBrush = newRenderTarget.CreateRadialGradientBrush(
new RadialGradientBrushProperties(
((RadialGradientBrush)sourceBrush).Center,
((RadialGradientBrush)sourceBrush).GradientOriginOffset,
((RadialGradientBrush)sourceBrush).RadiusX,
((RadialGradientBrush)sourceBrush).RadiusY),
newGSC,
new BrushProperties(sourceBrush.Opacity, sourceBrush.Transform));
sourceBrush.Dispose();
return newBrush;
}
if (sourceBrush is BitmapBrush)
{
newBrush = newRenderTarget.CreateBitmapBrush(
Bitmap,
new BitmapBrushProperties(
((BitmapBrush)sourceBrush).ExtendModeX,
((BitmapBrush)sourceBrush).ExtendModeY,
((BitmapBrush)sourceBrush).InterpolationMode),
new BrushProperties(sourceBrush.Opacity, sourceBrush.Transform));
sourceBrush.Dispose();
return newBrush;
}
throw new NotImplementedException("Unknown brush type used");
}