本文整理汇总了C#中Surface.Dispose方法的典型用法代码示例。如果您正苦于以下问题:C# Surface.Dispose方法的具体用法?C# Surface.Dispose怎么用?C# Surface.Dispose使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Surface
的用法示例。
在下文中一共展示了Surface.Dispose方法的8个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: RenderFrame
public void RenderFrame(Int16 width, Int16 height, Int16 arWidth, Int16 arHeight, uint pSurface)
{
IntPtr ptrMadVr = (IntPtr)pSurface;
Surface surfaceMadVr = new Surface(ptrMadVr);
try
{
unsafe
{
lock (GUIGraphicsContext.RenderModeSwitch)
{
if (grabber !=null)
grabber.OnFrame(width, height, arWidth, arHeight, (uint)surfaceMadVr.UnmanagedComPointer,
FrameGrabber.FrameSource.Video);
}
}
surfaceMadVr.ReleaseGraphics();
surfaceMadVr.Dispose();
}
catch (Exception ex)
{
surfaceMadVr.ReleaseGraphics();
surfaceMadVr.Dispose();
}
}
示例2: CompositeImage
public int CompositeImage(IntPtr pD3DDevice, IntPtr pddsRenderTarget, AMMediaType pmtRenderTarget, long rtStart, long rtEnd, int dwClrBkGnd, VMR9VideoStreamInfo[] pVideoStreamInfo, int cStreams)
{
try
{
// Just in case the filter call CompositeImage before InitCompositionDevice (this sometime occure)
if (unmanagedDevice != pD3DDevice)
{
SetManagedDevice(pD3DDevice);
}
// Create a managed Direct3D surface (the Render Target) from the unmanaged pointer.
// The constructor don't call IUnknown.AddRef but the "destructor" seem to call IUnknown.Release
// Direct3D seem to be happier with that according to the DirectX log
Marshal.AddRef(pddsRenderTarget);
Surface renderTarget = new Surface(pddsRenderTarget);
SurfaceDescription renderTargetDesc = renderTarget.Description;
Rectangle renderTargetRect = new Rectangle(0, 0, renderTargetDesc.Width, renderTargetDesc.Height);
// Same thing for the first video surface
// WARNING : This Compositor sample only use the video provided to the first pin.
Marshal.AddRef(pVideoStreamInfo[0].pddsVideoSurface);
Surface surface = new Surface(pVideoStreamInfo[0].pddsVideoSurface);
SurfaceDescription surfaceDesc = surface.Description;
Rectangle surfaceRect = new Rectangle(0, 0, surfaceDesc.Width, surfaceDesc.Height);
// Get the current time (to write it over the video later)
TimeSpan timeStart = TimeSpan.FromTicks(rtStart);
// Set the device's render target (this doesn't seem to be needed)
device.SetRenderTarget(0, renderTarget);
// Copy the whole video surface into the render target
// it's a de facto surface cleaning...
device.StretchRectangle(surface, surfaceRect, renderTarget, renderTargetRect, TextureFilter.None);
// sprite's methods need to be called between device.BeginScene and device.EndScene
device.BeginScene();
// Init the sprite engine for AlphaBlending operations
sprite.Begin(SpriteFlags.AlphaBlend | SpriteFlags.DoNotSaveState);
// Write the current video time (using the sprite)...
d3dFont.DrawText(sprite, timeStart.ToString(), Point.Empty, Color.White);
// Compute the spider moves
if (spiderPos.X == 0) spiderMove.X = +1;
if (spiderPos.X + spiderSize.Width > renderTargetDesc.Width) spiderMove.X = -1;
spiderPos.X += spiderMove.X;
if (spiderPos.Y == 0) spiderMove.Y = +1;
if (spiderPos.Y + spiderSize.Height > renderTargetDesc.Height) spiderMove.Y = -1;
spiderPos.Y += spiderMove.Y;
// Draw the spider
// sprite.Draw2D(spiderTex, Rectangle.Empty, Rectangle.Empty, spiderPos, -1);
// Draw2D seem buggy. Many thanks to Hitbox for finding that !
// https://sourceforge.net/forum/message.php?msg_id=4528466
sprite.Draw(spiderTex, Vector3.Empty, spiderPos, -1);
// End the spite engine (drawings take place here)
sprite.Flush();
sprite.End();
// End the sceen.
device.EndScene();
// No Present requiered because the rendering is on a render target...
// device.Present();
// Dispose the managed surface
surface.Dispose();
surface = null;
// and the managed render target
renderTarget.Dispose();
renderTarget = null;
}
catch(Exception e)
{
Debug.WriteLine(e.ToString());
}
// return a success to the filter
return 0;
}
示例3: PerformAction
public bool PerformAction()
{
bool success = true;
if (this.documentWorkspace.Selection.IsEmpty ||
!(this.documentWorkspace.ActiveLayer is BitmapLayer))
{
return false;
}
try
{
using (new WaitCursorChanger(this.documentWorkspace))
{
Utility.GCFullCollect();
PdnRegion selectionRegion = this.documentWorkspace.Selection.CreateRegion();
PdnGraphicsPath selectionOutline = this.documentWorkspace.Selection.CreatePath();
BitmapLayer activeLayer = (BitmapLayer)this.documentWorkspace.ActiveLayer;
RenderArgs renderArgs = new RenderArgs(activeLayer.Surface);
MaskedSurface maskedSurface = new MaskedSurface(renderArgs.Surface, selectionOutline);
SurfaceForClipboard surfaceForClipboard = new SurfaceForClipboard(maskedSurface);
Rectangle selectionBounds = Utility.GetRegionBounds(selectionRegion);
if (selectionBounds.Width > 0 && selectionBounds.Height > 0)
{
Surface copySurface = new Surface(selectionBounds.Width, selectionBounds.Height);
Bitmap copyBitmap = copySurface.CreateAliasedBitmap();
Bitmap copyOpaqueBitmap = new Bitmap(copySurface.Width, copySurface.Height, PixelFormat.Format24bppRgb);
using (Graphics copyBitmapGraphics = Graphics.FromImage(copyBitmap))
{
copyBitmapGraphics.Clear(Color.White);
}
maskedSurface.Draw(copySurface, -selectionBounds.X, -selectionBounds.Y);
using (Graphics copyOpaqueBitmapGraphics = Graphics.FromImage(copyOpaqueBitmap))
{
copyOpaqueBitmapGraphics.Clear(Color.White);
copyOpaqueBitmapGraphics.DrawImage(copyBitmap, 0, 0);
}
DataObject dataObject = new DataObject();
dataObject.SetData(DataFormats.Bitmap, copyOpaqueBitmap);
dataObject.SetData(surfaceForClipboard);
int retryCount = 2;
while (retryCount >= 0)
{
try
{
using (new WaitCursorChanger(this.documentWorkspace))
{
Clipboard.SetDataObject(dataObject, true);
}
break;
}
catch
{
if (retryCount == 0)
{
success = false;
Utility.ErrorBox(this.documentWorkspace,
PdnResources.GetString("CopyAction.Error.TransferToClipboard"));
}
else
{
Thread.Sleep(200);
}
}
finally
{
--retryCount;
}
}
copySurface.Dispose();
copyBitmap.Dispose();
copyOpaqueBitmap.Dispose();
}
selectionRegion.Dispose();
selectionOutline.Dispose();
renderArgs.Dispose();
maskedSurface.Dispose();
}
}
catch (OutOfMemoryException)
{
success = false;
Utility.ErrorBox(this.documentWorkspace, PdnResources.GetString("CopyAction.Error.OutOfMemory"));
}
catch (Exception)
//.........这里部分代码省略.........
示例4: DrawToGraphics
private void DrawToGraphics(Graphics g)
{
PointF clientPos = new PointF(
(this.position.X * this.dragAreaRect.Width) / ClientSize.Width,
(this.position.Y * this.dragAreaRect.Height) / ClientSize.Height);
PointF ptCenter = new PointF(ClientSize.Width / 2.0f, ClientSize.Height / 2.0f);
PointF ptDot = new PointF((1 + clientPos.X) * ClientSize.Width / 2.0f, (1 + clientPos.Y) * ClientSize.Height / 2.0f);
PointF ptArrow;
if (-1 <= clientPos.X && clientPos.X <= 1 &&
-1 <= clientPos.Y && clientPos.Y <= 1)
{
ptArrow = new PointF((1 + clientPos.X) * ClientSize.Width / 2, (1 + clientPos.Y) * ClientSize.Height / 2);
}
else
{
ptArrow = new PointF((1 + clientPos.X) * ClientSize.Width / 2, (1 + clientPos.Y) * ClientSize.Height / 2);
if (Math.Abs(clientPos.X) > Math.Abs(clientPos.Y))
{
if (clientPos.X > 0)
{
ptArrow.X = ClientSize.Width - 1;
ptArrow.Y = (1 + clientPos.Y / clientPos.X) * ClientSize.Height / 2;
}
else
{
ptArrow.X = 0;
ptArrow.Y = (1 - clientPos.Y / clientPos.X) * ClientSize.Height / 2;
}
}
else
{
if (clientPos.Y > 0)
{
ptArrow.X = (1 + clientPos.X / clientPos.Y) * ClientSize.Width / 2;
ptArrow.Y = ClientSize.Height - 1;
}
else
{
ptArrow.X = (1 - clientPos.X / clientPos.Y) * ClientSize.Width / 2;
ptArrow.Y = 0;
}
}
}
CompositingMode oldCM = g.CompositingMode;
g.CompositingMode = CompositingMode.SourceCopy;
g.Clear(this.BackColor);
g.CompositingMode = CompositingMode.SourceOver;
if (this.staticImageUnderlay != null)
{
Size dstSize;
if (this.cachedUnderlay != null)
{
dstSize = new Size(this.cachedUnderlay.Width, this.cachedUnderlay.Height);
}
else
{
Image image = this.staticImageUnderlay.Reference;
Rectangle srcRect = new Rectangle(0, 0, image.Width, image.Height);
Size maxThumbSize = new Size(
Math.Max(1, Math.Min(ClientSize.Width - 4, srcRect.Width)),
Math.Max(1, Math.Min(ClientSize.Height - 4, srcRect.Height)));
dstSize = Utility.ComputeThumbnailSize(image.Size, Math.Min(maxThumbSize.Width, maxThumbSize.Height));
this.cachedUnderlay = new Bitmap(dstSize.Width, dstSize.Height, PixelFormat.Format24bppRgb);
Surface checkers = new Surface(dstSize);
checkers.ClearWithCheckboardPattern();
Bitmap checkersBmp = checkers.CreateAliasedBitmap();
Rectangle gcuRect = new Rectangle(0, 0, this.cachedUnderlay.Width, this.cachedUnderlay.Height);
using (Graphics gcu = Graphics.FromImage(this.cachedUnderlay))
{
gcu.CompositingMode = CompositingMode.SourceOver;
gcu.DrawImage(checkersBmp, gcuRect, new Rectangle(0, 0, checkersBmp.Width, checkersBmp.Height), GraphicsUnit.Pixel);
gcu.InterpolationMode = InterpolationMode.HighQualityBicubic;
RectangleF gcuRect2 = RectangleF.Inflate(gcuRect, 0.5f, 0.5f);
gcu.DrawImage(image, gcuRect2, srcRect, GraphicsUnit.Pixel);
}
checkersBmp.Dispose();
checkersBmp = null;
checkers.Dispose();
checkers = null;
}
Rectangle dstRect = new Rectangle((ClientSize.Width - dstSize.Width) / 2, (ClientSize.Height - dstSize.Height) / 2, dstSize.Width, dstSize.Height);
g.DrawImage(this.cachedUnderlay, dstRect, new Rectangle(0, 0, this.cachedUnderlay.Width, this.cachedUnderlay.Height), GraphicsUnit.Pixel);
g.DrawRectangle(Pens.Black, new Rectangle(dstRect.Left - 1, dstRect.Top - 1, dstRect.Width + 1, dstRect.Height + 1));
//.........这里部分代码省略.........
示例5: CreateThumbnail
public static Surface CreateThumbnail(Surface sourceSurface, PdnGraphicsPath maskPath, Rectangle bounds, int thumbSideLength)
{
Size thumbSize = Utility.ComputeThumbnailSize(bounds.Size, thumbSideLength);
Surface thumb = new Surface(Math.Max(5, thumbSize.Width + 4), Math.Max(5, thumbSize.Height + 4));
thumb.Clear(ColorBgra.Transparent);
thumb.Clear(new Rectangle(1, 1, thumb.Width - 2, thumb.Height - 2), ColorBgra.Black);
Rectangle insetRect = new Rectangle(2, 2, thumb.Width - 4, thumb.Height - 4);
Surface thumbInset = thumb.CreateWindow(insetRect);
thumbInset.Clear(ColorBgra.Transparent);
float scaleX = (float)thumbInset.Width / (float)bounds.Width;
float scaleY = (float)thumbInset.Height / (float)bounds.Height;
Matrix scaleMatrix = new Matrix();
scaleMatrix.Translate(-bounds.X, -bounds.Y, System.Drawing.Drawing2D.MatrixOrder.Append);
scaleMatrix.Scale(scaleX, scaleY, System.Drawing.Drawing2D.MatrixOrder.Append);
thumbInset.SuperSamplingFitSurface(sourceSurface);
Surface maskInset = new Surface(thumbInset.Size);
maskInset.Clear(ColorBgra.Black);
using (RenderArgs maskInsetRA = new RenderArgs(maskInset))
{
maskInsetRA.Graphics.SmoothingMode = SmoothingMode.AntiAlias;
maskInsetRA.Graphics.Transform = scaleMatrix;
maskInsetRA.Graphics.FillPath(Brushes.White, maskPath);
maskInsetRA.Graphics.DrawPath(Pens.White, maskPath);
}
scaleMatrix.Dispose();
scaleMatrix = null;
IntensityMaskOp maskOp = new IntensityMaskOp();
maskOp.Apply(maskInset, thumbInset, maskInset);
UserBlendOps.NormalBlendOp normalOp = new UserBlendOps.NormalBlendOp();
thumbInset.ClearWithCheckboardPattern();
normalOp.Apply(thumbInset, thumbInset, maskInset);
maskInset.Dispose();
maskInset = null;
thumbInset.Dispose();
thumbInset = null;
using (RenderArgs thumbRA = new RenderArgs(thumb))
{
Utility.DrawDropShadow1px(thumbRA.Graphics, thumb.Bounds);
}
return thumb;
}
示例6: ResizeDocument
private void ResizeDocument()
{
this.pleaseStop = false;
// This is only sort of a hack: we must try and allocate enough for 2 extra layer-sized buffers
// Then we free them immediately. This is just so that if we don't have enough memory that we'll
// fail sooner rather than later.
Surface s1 = new Surface(this.newSize);
Surface s2 = new Surface(this.newSize);
try
{
foreach (Layer layer in src.Layers)
{
if (this.pleaseStop)
{
this.returnVal = false;
return;
}
if (layer is BitmapLayer)
{
Layer newLayer = ResizeLayer((BitmapLayer)layer, this.newSize.Width, this.newSize.Height, this.algorithm,
this.tilesPerLayer, new Procedure(RenderedRectHandler), ref this.pleaseStop);
if (newLayer == null)
{
this.returnVal = false;
return;
}
dst.Layers.Add(newLayer);
}
else
{
throw new InvalidOperationException("Resize does not support Layers that are not BitmapLayers");
}
}
}
finally
{
s1.Dispose();
s2.Dispose();
}
this.returnVal = true;
}
示例7: ResizeLayer
private static BitmapLayer ResizeLayer(BitmapLayer layer, int width, int height, ResamplingAlgorithm algorithm,
int tileCount, Procedure progressCallback, ref bool pleaseStopMonitor)
{
Surface surface = new Surface(width, height);
surface.Clear(ColorBgra.FromBgra(255, 255, 255, 0));
PaintDotNet.Threading.ThreadPool threadPool = new PaintDotNet.Threading.ThreadPool();
int rectCount;
if (tileCount == 0)
{
rectCount = Processor.LogicalCpuCount;
}
else
{
rectCount = tileCount;
}
Rectangle[] rects = new Rectangle[rectCount];
Utility.SplitRectangle(surface.Bounds, rects);
FitSurfaceContext fsc = new FitSurfaceContext(surface, layer.Surface, rects, algorithm);
if (progressCallback != null)
{
fsc.RenderedRect += progressCallback;
}
WaitCallback callback = new WaitCallback(fsc.FitSurface);
for (int i = 0; i < rects.Length; ++i)
{
if (pleaseStopMonitor)
{
break;
}
else
{
threadPool.QueueUserWorkItem(callback, BoxedConstants.GetInt32(i));
}
}
threadPool.Drain();
threadPool.DrainExceptions();
if (pleaseStopMonitor)
{
surface.Dispose();
surface = null;
}
BitmapLayer newLayer;
if (surface == null)
{
newLayer = null;
}
else
{
newLayer = new BitmapLayer(surface, true);
newLayer.LoadProperties(layer.SaveProperties());
}
if (progressCallback != null)
{
fsc.RenderedRect -= progressCallback;
}
return newLayer;
}
示例8: CreateSurface
protected override Surface CreateSurface()
{
if (player == null || player.Surface == null)
return null;
Surface surf;
surf = new Surface (player.Surface);
if (scale
&& (player.Width != Width
|| player.Height != Height)) {
double horiz_zoom = (double)Width / player.Width;
double vert_zoom = (double)Height / player.Height;
double zoom;
if (horiz_zoom < vert_zoom)
zoom = horiz_zoom;
else
zoom = vert_zoom;
surf.Scale (zoom);
}
if (dim != 0) {
Surface dim_surf = new Surface (surf.Size);
dim_surf.Alpha = dim;
dim_surf.AlphaBlending = true;
dim_surf.Blit (surf);
surf.Dispose ();
surf = dim_surf;
}
return surf;
}