本文整理汇总了C#中PaintDotNet.Surface.Clear方法的典型用法代码示例。如果您正苦于以下问题:C# Surface.Clear方法的具体用法?C# Surface.Clear怎么用?C# Surface.Clear使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类PaintDotNet.Surface
的用法示例。
在下文中一共展示了Surface.Clear方法的12个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: OnSave
protected override void OnSave(Document input, Stream output, SaveConfigToken token, Surface scratchSurface, ProgressEventHandler progressCallback)
{
GifSaveConfigToken gsct = (GifSaveConfigToken)token;
// Flatten and pre-process the image
scratchSurface.Clear(ColorBgra.FromBgra(255, 255, 255, 0));
using (RenderArgs ra = new RenderArgs(scratchSurface))
{
input.Render(ra, true);
}
for (int y = 0; y < scratchSurface.Height; ++y)
{
unsafe
{
ColorBgra* ptr = scratchSurface.GetRowAddressUnchecked(y);
for (int x = 0; x < scratchSurface.Width; ++x)
{
if (ptr->A < gsct.Threshold)
{
ptr->Bgra = 0;
}
else
{
if (gsct.PreMultiplyAlpha)
{
int r = ((ptr->R * ptr->A) + (255 * (255 - ptr->A))) / 255;
int g = ((ptr->G * ptr->A) + (255 * (255 - ptr->A))) / 255;
int b = ((ptr->B * ptr->A) + (255 * (255 - ptr->A))) / 255;
int a = 255;
*ptr = ColorBgra.FromBgra((byte)b, (byte)g, (byte)r, (byte)a);
}
else
{
ptr->Bgra |= 0xff000000;
}
}
++ptr;
}
}
}
using (Bitmap quantized = Quantize(scratchSurface, gsct.DitherLevel, 255, progressCallback))
{
quantized.Save(output, ImageFormat.Gif);
}
}
示例2: OnSave
protected override unsafe void OnSave( Document input, Stream output, SaveConfigToken token, Surface scratchSurface, ProgressEventHandler callback )
{
DdsSaveConfigToken ddsToken = ( DdsSaveConfigToken )token;
// We need to be able to feast on the goo inside..
scratchSurface.Clear( ColorBgra.Transparent );
using ( RenderArgs ra = new RenderArgs( scratchSurface ) )
{
input.Render( ra, true );
}
// Create the DDS file, and save it..
DdsFile ddsFile = new DdsFile();
ddsFile.Save( output, scratchSurface, ddsToken, callback );
}
示例3: Save
public static void Save(Document input, Stream output, Surface scratchSurface, ImageFormat format, ProgressEventHandler callback)
{
// flatten the document
scratchSurface.Clear(ColorBgra.FromBgra(0, 0, 0, 0));
using (RenderArgs ra = new RenderArgs(scratchSurface))
{
input.Render(ra, true);
}
using (Bitmap bitmap = scratchSurface.CreateAliasedBitmap())
{
LoadProperties(bitmap, input);
bitmap.Save(output, format);
}
}
示例4: OnSaveT
protected override void OnSaveT(Document input, Stream output, PropertyBasedSaveConfigToken token, Surface scratchSurface, ProgressEventHandler progressCallback)
{
int quality = token.GetProperty<Int32Property>(PropertyNames.Quality).Value;
ImageCodecInfo icf = GdiPlusFileType.GetImageCodecInfo(ImageFormat.Jpeg);
EncoderParameters parms = new EncoderParameters(1);
EncoderParameter parm = new EncoderParameter(System.Drawing.Imaging.Encoder.Quality, quality);
parms.Param[0] = parm;
scratchSurface.Clear(ColorBgra.White);
using (RenderArgs ra = new RenderArgs(scratchSurface))
{
input.Render(ra, false);
}
using (Bitmap bitmap = scratchSurface.CreateAliasedBitmap())
{
GdiPlusFileType.LoadProperties(bitmap, input);
bitmap.Save(output, icf, parms);
}
}
示例5: OnSave
protected override void OnSave(Document input, Stream output, SaveConfigToken token, Surface scratchSurface, ProgressEventHandler callback)
{
JpegSaveConfigToken jsct = (JpegSaveConfigToken)token;
ImageCodecInfo icf = GdiPlusFileType.GetImageCodecInfo(ImageFormat.Jpeg);
EncoderParameters parms = new EncoderParameters(1);
EncoderParameter parm = new EncoderParameter(System.Drawing.Imaging.Encoder.Quality, jsct.Quality); // force '95% quality'
parms.Param[0] = parm;
scratchSurface.Clear(ColorBgra.White);
using (RenderArgs ra = new RenderArgs(scratchSurface))
{
input.Render(ra, true);
}
using (Bitmap bitmap = scratchSurface.CreateAliasedBitmap())
{
GdiPlusFileType.LoadProperties(bitmap, input);
bitmap.Save(output, icf, parms);
}
}
示例6: OnSave
protected override void OnSave(Document input, Stream output, SaveConfigToken token, Surface scratchSurface, ProgressEventHandler callback)
{
ImageCodecInfo icf = GdiPlusFileType.GetImageCodecInfo(ImageFormat.Bmp);
EncoderParameters parms = new EncoderParameters(1);
EncoderParameter parm = new EncoderParameter(System.Drawing.Imaging.Encoder.ColorDepth, 24); // BMP's should always save as 24-bit
parms.Param[0] = parm;
scratchSurface.Clear(ColorBgra.White);
using (RenderArgs ra = new RenderArgs(scratchSurface))
{
input.Render(ra, true);
}
// In order to save memory, we 'squish' the 32-bit bitmap down to 24-bit in-place
// instead of allocating a new bitmap and copying it over.
SquishSurfaceTo24Bpp(scratchSurface);
using (Bitmap bitmap = CreateAliased24BppBitmap(scratchSurface))
{
GdiPlusFileType.LoadProperties(bitmap, input);
bitmap.Save(output, icf, parms);
}
}
示例7: Flatten
public void Flatten(Surface dst)
{
if (dst.Size != this.Size)
{
throw new ArgumentOutOfRangeException("dst.Size must match this.Size");
}
dst.Clear(ColorBgra.White.NewAlpha(0));
using (RenderArgs renderArgs = new RenderArgs(dst))
{
Render(renderArgs, true);
}
}
示例8: RenderThumbnail
public Surface RenderThumbnail(int maxEdgeLength, bool highQuality, bool forceUpToDate)
{
if (Document == null)
{
Surface ret = new Surface(maxEdgeLength, maxEdgeLength);
ret.Clear(ColorBgra.Transparent);
return ret;
}
Size thumbSize = Utility.ComputeThumbnailSize(Document.Size, maxEdgeLength);
Surface thumb = new Surface(thumbSize);
thumb.Clear(ColorBgra.Transparent);
RenderCompositionTo(thumb, highQuality, forceUpToDate);
return thumb;
}
示例9: AddToMruList
/// <summary>
/// Takes the current Document from this DocumentWorkspace instance and adds it to the MRU list.
/// </summary>
/// <param name="fileName"></param>
public void AddToMruList()
{
using (new PushNullToolMode(this))
{
string fullFileName = Path.GetFullPath(this.FilePath);
int edgeLength = AppWorkspace.MostRecentFiles.IconSize;
Surface thumb1 = RenderThumbnail(edgeLength, true, true);
// Put it inside a square bitmap
Surface thumb = new Surface(4 + edgeLength, 4 + edgeLength);
thumb.Clear(ColorBgra.Transparent);
Rectangle dstRect = new Rectangle((thumb.Width - thumb1.Width) / 2,
(thumb.Height - thumb1.Height) / 2, thumb1.Width, thumb1.Height);
thumb.CopySurface(thumb1, dstRect.Location);
using (RenderArgs ra = new RenderArgs(thumb))
{
// Draw black border
Rectangle borderRect = new Rectangle(dstRect.Left - 1, dstRect.Top - 1, dstRect.Width + 2, dstRect.Height + 2);
--borderRect.Width;
--borderRect.Height;
ra.Graphics.DrawRectangle(Pens.Black, borderRect);
Rectangle shadowRect = Rectangle.Inflate(borderRect, 1, 1);
++shadowRect.Width;
++shadowRect.Height;
Utility.DrawDropShadow1px(ra.Graphics, shadowRect);
thumb1.Dispose();
thumb1 = null;
MostRecentFile mrf = new MostRecentFile(fullFileName, Utility.FullCloneBitmap(ra.Bitmap));
if (AppWorkspace.MostRecentFiles.Contains(fullFileName))
{
AppWorkspace.MostRecentFiles.Remove(fullFileName);
}
AppWorkspace.MostRecentFiles.Add(mrf);
AppWorkspace.MostRecentFiles.SaveMruList();
}
}
}
示例10: RenderTo
public void RenderTo(Surface dst)
{
dst.Clear(ColorBgra.Transparent);
if (this.surface != null)
{
SurfaceBoxRendererList sbrl = new SurfaceBoxRendererList(this.surface.Size, dst.Size);
SurfaceBoxBaseRenderer sbbr = new SurfaceBoxBaseRenderer(sbrl, this.surface);
sbrl.Add(sbbr, true);
sbrl.Render(dst, new Point(0, 0));
sbrl.Remove(sbbr);
}
}
示例11: OnSave
protected override void OnSave(Document input, Stream output, SaveConfigToken token, Surface scratchSurface, ProgressEventHandler callback)
{
scratchSurface.Clear(ColorBgra.FromBgra(255, 255, 255, 0));
using (RenderArgs ra = new RenderArgs(scratchSurface))
{
input.Render(ra, true);
}
SaveTga(scratchSurface, output, token, callback);
}
示例12: 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;
}