本文整理汇总了C#中SharpDX.Direct3D9.Sprite.End方法的典型用法代码示例。如果您正苦于以下问题:C# Sprite.End方法的具体用法?C# Sprite.End怎么用?C# Sprite.End使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类SharpDX.Direct3D9.Sprite
的用法示例。
在下文中一共展示了Sprite.End方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: ConvertToBitmap
public Bitmap ConvertToBitmap(string filePath)
{
using (var texture = Texture.FromFile(device, filePath)) {
var surfaceDescription = texture.GetLevelDescription(0);
var textureWidth = surfaceDescription.Width;
var textureHeight = surfaceDescription.Height;
using (var renderTarget = Surface.CreateRenderTarget(device, textureWidth, textureHeight, Format.X8R8G8B8, MultisampleType.None, 0, true)) {
var oldBackBuffer = device.GetRenderTarget(0);
device.SetRenderTarget(0, renderTarget);
using (var sprite = new Sprite(device)) {
device.BeginScene();
sprite.Begin(SpriteFlags.AlphaBlend);
sprite.Draw(texture, new ColorBGRA(Vector4.One));
sprite.End();
device.EndScene();
}
device.SetRenderTarget(0, oldBackBuffer);
var renderTargetData = renderTarget.LockRectangle(LockFlags.ReadOnly);
var resultBitmap = new Bitmap(textureWidth, textureHeight);
var resultData = resultBitmap.LockBits(new Rectangle(0, 0, textureWidth, textureHeight), ImageLockMode.WriteOnly, PixelFormat.Format32bppRgb);
for (var y = 0; y < textureHeight; y++) {
Utilities.CopyMemory(resultData.Scan0 + y * resultData.Stride, renderTargetData.DataPointer + y * renderTargetData.Pitch, textureWidth * 4);
}
resultBitmap.UnlockBits(resultData);
renderTarget.UnlockRectangle();
return resultBitmap;
}
}
}
示例2: DrawOverlay
public void DrawOverlay(Texture targetTexture)
{
Subtitle currentSubtitle;
lock (_syncObj)
{
currentSubtitle = _subtitles.ToList().FirstOrDefault(s => s.ShouldDraw);
if (currentSubtitle == null)
return;
if (targetTexture == null || targetTexture.IsDisposed || currentSubtitle.SubTexture == null || currentSubtitle.SubTexture.IsDisposed)
{
if (_drawCount > 0)
ServiceRegistration.Get<ILogger>().Debug("Draw count for last sub: {0}", _drawCount);
_drawCount = 0;
return;
}
_drawCount++;
}
try
{
// TemporaryRenderTarget changes RenderTarget to texture and restores settings when done (Dispose)
using (new TemporaryRenderTarget(targetTexture))
using (TemporaryRenderState temporaryRenderState = new TemporaryRenderState())
using (Sprite sprite = new Sprite(_device))
{
sprite.Begin(SpriteFlags.AlphaBlend);
// No alpha test here, allow all values
temporaryRenderState.SetTemporaryRenderState(RenderState.AlphaTestEnable, 0);
// Use the SourceAlpha channel and InverseSourceAlpha for destination
temporaryRenderState.SetTemporaryRenderState(RenderState.BlendOperation, (int)BlendOperation.Add);
temporaryRenderState.SetTemporaryRenderState(RenderState.SourceBlend, (int)Blend.SourceAlpha);
temporaryRenderState.SetTemporaryRenderState(RenderState.DestinationBlend, (int)Blend.InverseSourceAlpha);
// Check the target texture dimensions and adjust scaling and translation
SurfaceDescription desc = targetTexture.GetLevelDescription(0);
Matrix transform = Matrix.Identity;
// Position subtitle and scale it to match video frame size, if required
transform *= Matrix.Translation(currentSubtitle.HorizontalPosition, currentSubtitle.FirstScanLine, 0);
if (currentSubtitle.ScreenWidth != desc.Width || currentSubtitle.ScreenHeight != desc.Height)
{
var factorW = (float)desc.Width / currentSubtitle.ScreenWidth;
var factorH = (float)desc.Height / currentSubtitle.ScreenHeight;
transform *= Matrix.Scaling(factorW, factorH, 1);
}
sprite.Transform = transform;
sprite.Draw(currentSubtitle.SubTexture, SharpDX.Color.White);
sprite.End();
}
if (_onTextureInvalidated != null)
_onTextureInvalidated();
}
catch (Exception ex)
{
ServiceRegistration.Get<ILogger>().Debug("Error in DrawOverlay", ex);
}
}
示例3: DrawOverlay
public void DrawOverlay(Surface targetSurface)
{
Texture subTexture;
Subtitle currentSubtitle;
lock (_syncObj)
{
currentSubtitle = _currentSubtitle;
subTexture = _subTexture;
// Available sub is not due
if (currentSubtitle == null || !currentSubtitle.ShouldDraw)
return;
if (targetSurface == null || targetSurface.IsDisposed || subTexture == null)
{
if (_drawCount > 0)
ServiceRegistration.Get<ILogger>().Debug("Draw count for last sub: {0}", _drawCount);
_drawCount = 0;
return;
}
_drawCount++;
}
try
{
if (!subTexture.IsDisposed)
{
// TemporaryRenderTarget changes RenderTarget to texture and restores settings when done (Dispose)
using (new TemporaryRenderTarget(targetSurface))
using (TemporaryRenderState temporaryRenderState = new TemporaryRenderState())
using (Sprite sprite = new Sprite(_device))
{
sprite.Begin(SpriteFlags.AlphaBlend);
// No alpha test here, allow all values
temporaryRenderState.SetTemporaryRenderState(RenderState.AlphaTestEnable, 0);
// Use the SourceAlpha channel and InverseSourceAlpha for destination
temporaryRenderState.SetTemporaryRenderState(RenderState.BlendOperation, (int) BlendOperation.Add);
temporaryRenderState.SetTemporaryRenderState(RenderState.SourceBlend, (int) Blend.SourceAlpha);
temporaryRenderState.SetTemporaryRenderState(RenderState.DestinationBlend, (int) Blend.InverseSourceAlpha);
// Check the target texture dimensions and adjust scaling and translation
SurfaceDescription desc = targetSurface.Description;
Matrix transform = Matrix.Identity;
transform *= Matrix.Translation(currentSubtitle.HorizontalPosition, currentSubtitle.FirstScanLine, 0);
// Subtitle could be smaller for 16:9 anamorphic video (subtitle width: 720, video texture: 1024)
// then we need to scale the subtitle width also.
if (currentSubtitle.ScreenWidth != desc.Width)
transform *= Matrix.Scaling((float) desc.Width / currentSubtitle.ScreenWidth, 1, 1);
sprite.Transform = transform;
sprite.Draw(subTexture, SharpDX.Color.White);
sprite.End();
}
}
}
catch (Exception ex)
{
ServiceRegistration.Get<ILogger>().Debug("Error in DrawOverlay", ex);
}
if (_onTextureInvalidated != null)
_onTextureInvalidated();
}