本文整理汇总了C#中Surface.CreateAliasedBitmap方法的典型用法代码示例。如果您正苦于以下问题:C# Surface.CreateAliasedBitmap方法的具体用法?C# Surface.CreateAliasedBitmap怎么用?C# Surface.CreateAliasedBitmap使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Surface
的用法示例。
在下文中一共展示了Surface.CreateAliasedBitmap方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: 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)
//.........这里部分代码省略.........
示例2: 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));
//.........这里部分代码省略.........