本文整理匯總了C#中SharpDX.Direct2D1.SolidColorBrush.Dispose方法的典型用法代碼示例。如果您正苦於以下問題:C# SolidColorBrush.Dispose方法的具體用法?C# SolidColorBrush.Dispose怎麽用?C# SolidColorBrush.Dispose使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類SharpDX.Direct2D1.SolidColorBrush
的用法示例。
在下文中一共展示了SolidColorBrush.Dispose方法的7個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的C#代碼示例。
示例1: DrawGlyphRun
public Result DrawGlyphRun(object clientDrawingContext, float baselineOriginX, float baselineOriginY, MeasuringMode measuringMode, GlyphRun glyphRun, GlyphRunDescription glyphRunDescription, ComObject clientDrawingEffect)
{
var pathGeometry = new PathGeometry(_d2DFactory);
var geometrySink = pathGeometry.Open();
var fontFace = glyphRun.FontFace;
if (glyphRun.Indices.Length > 0)
fontFace.GetGlyphRunOutline(glyphRun.FontSize, glyphRun.Indices, glyphRun.Advances, glyphRun.Offsets, glyphRun.IsSideways, glyphRun.BidiLevel % 2 != 0, geometrySink);
geometrySink.Close();
geometrySink.Dispose();
fontFace.Dispose();
var matrix = new Matrix3x2()
{
M11 = 1,
M12 = 0,
M21 = 0,
M22 = 1,
M31 = baselineOriginX,
M32 = baselineOriginY
};
var transformedGeometry = new TransformedGeometry(_d2DFactory, pathGeometry, matrix);
var brushColor = (Color4)Color.Black;
if (clientDrawingEffect != null && clientDrawingEffect is ColorDrawingEffect)
brushColor = (clientDrawingEffect as ColorDrawingEffect).Color;
var brush = new SolidColorBrush(_renderTarget, brushColor);
_renderTarget.DrawGeometry(transformedGeometry, brush);
_renderTarget.FillGeometry(transformedGeometry, brush);
pathGeometry.Dispose();
transformedGeometry.Dispose();
brush.Dispose();
return SharpDX.Result.Ok;
}
示例2: CreateTextSprite
//.........這裏部分代碼省略.........
: (CCVerticalTextAlignment.Top == verticleAlignement) ? 0 // align to top
: (imageHeight - boundingRect.Bottom) * 0.5f; // align to center
SharpDX.WIC.Bitmap sharpBitmap = null;
WicRenderTarget sharpRenderTarget = null;
SolidColorBrush solidBrush = null;
try
{
// Select our pixel format
var pixelFormat = SharpDX.WIC.PixelFormat.Format32bppPRGBA;
// create our backing bitmap
sharpBitmap = new SharpDX.WIC.Bitmap(FactoryImaging, imageWidth, imageHeight, pixelFormat, BitmapCreateCacheOption.CacheOnLoad);
// Create the render target that we will draw to
sharpRenderTarget = new WicRenderTarget(Factory2D, sharpBitmap, new RenderTargetProperties());
// Create our brush to actually draw with
solidBrush = new SolidColorBrush(sharpRenderTarget, foregroundColor);
// Begin the drawing
sharpRenderTarget.BeginDraw();
if (textDefinition.isShouldAntialias)
sharpRenderTarget.AntialiasMode = AntialiasMode.Aliased;
// Clear it
sharpRenderTarget.Clear(TransparentColor);
// Draw the text to the bitmap
sharpRenderTarget.DrawTextLayout(new Vector2(boundingRect.X, yOffset), textLayout, solidBrush);
// End our drawing which will commit the rendertarget to the bitmap
sharpRenderTarget.EndDraw();
// Debugging purposes
//var s = "Label4";
//SaveToFile(@"C:\Xamarin\" + s + ".png", _bitmap, _renderTarget);
// The following code creates a .png stream in memory of our Bitmap and uses it to create our Textue2D
Texture2D tex = null;
using (var memStream = new MemoryStream())
{
using (var encoder = new PngBitmapEncoder(FactoryImaging, memStream))
using (var frameEncoder = new BitmapFrameEncode(encoder))
{
frameEncoder.Initialize();
frameEncoder.WriteSource(sharpBitmap);
frameEncoder.Commit();
encoder.Commit();
}
// Create the Texture2D from the png stream
tex = Texture2D.FromStream(CCDrawManager.SharedDrawManager.XnaGraphicsDevice, memStream);
}
// Return our new CCTexture2D created from the Texture2D which will have our text drawn on it.
return new CCTexture2D(tex);
}
catch (Exception exc)
{
CCLog.Log("CCLabel-Windows: Unable to create the backing image of our text. Message: {0}", exc.StackTrace);
}
finally
{
if (sharpBitmap != null)
{
sharpBitmap.Dispose();
sharpBitmap = null;
}
if (sharpRenderTarget != null)
{
sharpRenderTarget.Dispose();
sharpRenderTarget = null;
}
if (solidBrush != null)
{
solidBrush.Dispose();
solidBrush = null;
}
if (textFormat != null)
{
textFormat.Dispose();
textFormat = null;
}
if (textLayout != null)
{
textLayout.Dispose();
textLayout = null;
}
}
// If we have reached here then something has gone wrong.
return new CCTexture2D();
}
示例3: DisplayName
public void DisplayName(string name)
{
var brush = new SolidColorBrush(renderTarget, Color4.White);
var layoutRect = new SharpDX.RectangleF(0, 0, bounds.Width, bounds.Height);
renderTarget.BeginDraw();
renderTarget.Clear(Color4.Black);
renderTarget.DrawRectangle(new SharpDX.RectangleF(0, 0, bounds.Width, bounds.Height), brush, 10f);
renderTarget.DrawText(name, textFormat, layoutRect, solidColorBrush);
//int nx = 4;
//int ny = 4;
//for (int i = 0; i < nx - 1; i++)
// for (int j = 0; j < ny - 1; j++)
// {
// float x = (float)bounds.Width / (float)nx * (i + 1);
// float y = (float)bounds.Height / (float)ny * (j + 1);
// const int w = 10;
// renderTarget.DrawLine(new Vector2(x - w, y), new Vector2(x + w, y), brush, 1);
// renderTarget.DrawLine(new Vector2(x, y - w), new Vector2(x, y + w), brush, 1);
// }
int nx = 4;
int ny = 4;
for (int i = 0; i < nx - 1; i++)
{
float x = (float)bounds.Width / (float)nx * (i + 1);
renderTarget.DrawLine(new Vector2(x, 0), new Vector2(x, bounds.Height), brush, 1);
}
for (int i = 0; i < ny - 1; i++)
{
float y = (float)bounds.Height / (float)ny * (i + 1);
renderTarget.DrawLine(new Vector2(0, y), new Vector2(bounds.Width, y), brush, 1);
}
renderTarget.EndDraw();
brush.Dispose();
}
示例4: Main
//.........這裏部分代碼省略.........
// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
// EFFECT SETUP ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
// Effect 1 : BitmapSource - take decoded image data and get a BitmapSource from it
var bitmapSourceEffect = new d2.Effects.BitmapSource(d2dContext);
bitmapSourceEffect.WicBitmapSource = formatConverter;
// Effect 2 : GaussianBlur - give the bitmapsource a gaussian blurred effect
var gaussianBlurEffect = new d2.Effects.GaussianBlur(d2dContext);
gaussianBlurEffect.SetInput(0, bitmapSourceEffect.Output, true);
gaussianBlurEffect.StandardDeviation = 5f;
// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
// OVERLAY TEXT SETUP ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
var textFormat = new dw.TextFormat(dwFactory, "Arial", 15f); // create the text format of specified font configuration
// draw a long text to show the automatic line wrapping
var textToDraw = "Some long text to show the drawing of preformatted "
+ "glyphs using DirectWrite on the Direct2D surface."
+ " Notice the automatic wrapping of line if it exceeds desired width.";
// create the text layout - this improves the drawing performance for static text
// as the glyph positions are precalculated
var textLayout = new dw.TextLayout(dwFactory, textToDraw, textFormat, 300f, 1000f);
var textBrush = new d2.SolidColorBrush(d2dContext, Color.LightGreen);
// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
// RENDER TARGET SETUP ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
// create the d2d bitmap description using default flags (from SharpDX samples) and 96 DPI
var d2dBitmapProps = new d2.BitmapProperties1(d2PixelFormat, 96, 96, d2.BitmapOptions.Target | d2.BitmapOptions.CannotDraw);
// the render target
var d2dRenderTarget = new d2.Bitmap1(d2dContext, new Size2(pixelWidth, pixelHeight), d2dBitmapProps);
d2dContext.Target = d2dRenderTarget; // associate bitmap with the d2d context
// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
// DRAWING ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
// slow preparations - fast drawing:
d2dContext.BeginDraw();
d2dContext.DrawImage(gaussianBlurEffect);
d2dContext.DrawTextLayout(new Vector2(5f, 5f), textLayout, textBrush);
d2dContext.EndDraw();
// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
// IMAGE SAVING ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
// delete the output file if it already exists
if (System.IO.File.Exists(outputPath)) System.IO.File.Delete(outputPath);
// use the appropiate overload to write either to stream or to a file
var stream = new wic.WICStream(imagingFactory, outputPath, NativeFileAccess.Write);
// select the image encoding format HERE
var encoder = new wic.PngBitmapEncoder(imagingFactory);
encoder.Initialize(stream);
var bitmapFrameEncode = new wic.BitmapFrameEncode(encoder);
bitmapFrameEncode.Initialize();
bitmapFrameEncode.SetSize(pixelWidth, pixelHeight);
bitmapFrameEncode.SetPixelFormat(ref wicPixelFormat);
// this is the trick to write D2D1 bitmap to WIC
var imageEncoder = new wic.ImageEncoder(imagingFactory, d2dDevice);
imageEncoder.WriteFrame(d2dRenderTarget, bitmapFrameEncode, new wic.ImageParameters(d2PixelFormat, 96, 96, 0, 0, pixelWidth, pixelHeight));
bitmapFrameEncode.Commit();
encoder.Commit();
// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
// CLEANUP ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
// dispose everything and free used resources
bitmapFrameEncode.Dispose();
encoder.Dispose();
stream.Dispose();
textBrush.Dispose();
textLayout.Dispose();
textFormat.Dispose();
formatConverter.Dispose();
gaussianBlurEffect.Dispose();
bitmapSourceEffect.Dispose();
d2dRenderTarget.Dispose();
inputStream.Dispose();
decoder.Dispose();
d2dContext.Dispose();
dwFactory.Dispose();
imagingFactory.Dispose();
d2dDevice.Dispose();
dxgiDevice.Dispose();
d3dDevice.Dispose();
defaultDevice.Dispose();
// show the result
System.Diagnostics.Process.Start(outputPath);
}
示例5: Run
//.........這裏部分代碼省略.........
// ---------------------------------------------------------------------------------------------------
// Acquire the mutexes. These are needed to assure the device in use has exclusive access to the surface
// ---------------------------------------------------------------------------------------------------
var device10Mutex = textureD3D10.QueryInterface<KeyedMutex>();
var device11Mutex = textureD3D11.QueryInterface<KeyedMutex>();
// ---------------------------------------------------------------------------------------------------
// Main rendering loop
// ---------------------------------------------------------------------------------------------------
bool first = true;
RenderLoop
.Run(form,
() =>
{
if(first)
{
form.Activate();
first = false;
}
// clear the render target to black
context.ClearRenderTargetView(renderTargetView, Colors.DarkSlateGray);
// Draw the triangle
context.InputAssembler.InputLayout = layoutColor;
context.InputAssembler.PrimitiveTopology = PrimitiveTopology.TriangleList;
context.InputAssembler.SetVertexBuffers(0, new VertexBufferBinding(vertexBufferColor, VertexPositionColor.SizeInBytes, 0));
context.OutputMerger.BlendState = null;
var currentTechnique = effect.GetTechniqueByName("Color");
for (var pass = 0; pass < currentTechnique.Description.PassCount; ++pass)
{
using (var effectPass = currentTechnique.GetPassByIndex(pass))
{
System.Diagnostics.Debug.Assert(effectPass.IsValid, "Invalid EffectPass");
effectPass.Apply(context);
}
context.Draw(3, 0);
};
// Draw Ellipse on the shared Texture2D
device10Mutex.Acquire(0, 100);
renderTarget2D.BeginDraw();
renderTarget2D.Clear(Colors.Black);
renderTarget2D.DrawGeometry(tesselatedGeometry, solidColorBrush);
renderTarget2D.DrawEllipse(new Ellipse(center, 200, 200), solidColorBrush, 20, null);
renderTarget2D.EndDraw();
device10Mutex.Release(0);
// Draw the shared texture2D onto the screen, blending the 2d content in
device11Mutex.Acquire(0, 100);
var srv = new ShaderResourceView(device11, textureD3D11);
effect.GetVariableByName("g_Overlay").AsShaderResource().SetResource(srv);
context.InputAssembler.InputLayout = layoutOverlay;
context.InputAssembler.PrimitiveTopology = PrimitiveTopology.TriangleStrip;
context.InputAssembler.SetVertexBuffers(0, new VertexBufferBinding(vertexBufferOverlay, VertexPositionTexture.SizeInBytes, 0));
context.OutputMerger.BlendState = blendStateTransparent;
currentTechnique = effect.GetTechniqueByName("Overlay");
for (var pass = 0; pass < currentTechnique.Description.PassCount; ++pass)
{
using (var effectPass = currentTechnique.GetPassByIndex(pass))
{
System.Diagnostics.Debug.Assert(effectPass.IsValid, "Invalid EffectPass");
effectPass.Apply(context);
}
context.Draw(4, 0);
}
srv.Dispose();
device11Mutex.Release(0);
swapChain.Present(0, PresentFlags.None);
});
// dispose everything
vertexBufferColor.Dispose();
vertexBufferOverlay.Dispose();
layoutColor.Dispose();
layoutOverlay.Dispose();
effect.Dispose();
shaderByteCode.Dispose();
renderTarget2D.Dispose();
swapChain.Dispose();
device11.Dispose();
device10.Dispose();
textureD3D10.Dispose();
textureD3D11.Dispose();
factory1.Dispose();
adapter1.Dispose();
sharedResource.Dispose();
factory2D.Dispose();
surface.Dispose();
solidColorBrush.Dispose();
blendStateTransparent.Dispose();
device10Mutex.Dispose();
device11Mutex.Dispose();
}
示例6: DrawStrikethrough
public Result DrawStrikethrough(object clientDrawingContext, float baselineOriginX, float baselineOriginY, ref Strikethrough strikethrough, ComObject clientDrawingEffect)
{
var rect = new SharpDX.RectangleF(0, strikethrough.Offset, strikethrough.Width, strikethrough.Offset + strikethrough.Thickness);
var rectangleGeometry = new RectangleGeometry(_d2DFactory, rect);
var matrix = new Matrix3x2()
{
M11 = 1,
M12 = 0,
M21 = 0,
M22 = 1,
M31 = baselineOriginX,
M32 = baselineOriginY
};
var transformedGeometry = new TransformedGeometry(_d2DFactory, rectangleGeometry, matrix);
var brushColor = (Color4)Color.Black;
if (clientDrawingEffect != null && clientDrawingEffect is ColorDrawingEffect)
brushColor = (Color4)(clientDrawingEffect as ColorDrawingEffect).Color;
var brush = new SolidColorBrush(_renderTarget, brushColor);
_renderTarget.DrawGeometry(transformedGeometry, brush);
_renderTarget.FillGeometry(transformedGeometry, brush);
rectangleGeometry.Dispose();
transformedGeometry.Dispose();
brush.Dispose();
return Result.Ok;
}
示例7: DrawUnderline
public Result DrawUnderline(object clientDrawingContext, float baselineOriginX, float baselineOriginY, ref Underline underline, ComObject clientDrawingEffect)
{
var rect = new SharpDX.RectangleF(0, underline.Offset, underline.Width, underline.Offset + underline.Thickness);
var rectangleGeometry = new RectangleGeometry(_d2DFactory, rect);
var matrix = new Matrix3x2()
{
M11 = 1,
M12 = 0,
M21 = 0,
M22 = 1,
M31 = baselineOriginX,
M32 = baselineOriginY
};
var transformedGeometry = new TransformedGeometry(_d2DFactory, rectangleGeometry, matrix);
var brushColor = new Color4(1, 0, 0, 0);
if (clientDrawingEffect != null && clientDrawingEffect is ColorDrawingEffect)
brushColor = (clientDrawingEffect as ColorDrawingEffect).Color;
var brush = new SolidColorBrush(_renderTarget, brushColor);
_renderTarget.DrawGeometry(transformedGeometry, brush);
_renderTarget.FillGeometry(transformedGeometry, brush);
rectangleGeometry.Dispose();
transformedGeometry.Dispose();
brush.Dispose();
return SharpDX.Result.Ok;
}