当前位置: 首页>>代码示例>>C#>>正文


C# Surface.Clear方法代码示例

本文整理汇总了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);
            }
        }
开发者ID:nkaligin,项目名称:paint-mono,代码行数:51,代码来源:GifFileType.cs

示例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 );
		}
开发者ID:herbqiao,项目名称:paint.net,代码行数:16,代码来源:DdsFileType.cs

示例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);
            }
        }
开发者ID:metadeta96,项目名称:openpdn,代码行数:16,代码来源:GdiPlusFileType.cs

示例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);
            }
        }
开发者ID:herbqiao,项目名称:paint.net,代码行数:22,代码来源:JpegFileType.cs

示例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);
            }
        }
开发者ID:nkaligin,项目名称:paint-mono,代码行数:22,代码来源:JpegFileType.cs

示例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);
            }
        }
开发者ID:nkaligin,项目名称:paint-mono,代码行数:24,代码来源:BmpFileType.cs

示例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);
            }
        }
开发者ID:leejungho2,项目名称:xynotecgui,代码行数:14,代码来源:Document.cs

示例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;
        }
开发者ID:herbqiao,项目名称:paint.net,代码行数:17,代码来源:DocumentWorkspace.cs

示例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();
                }
            }
        }
开发者ID:herbqiao,项目名称:paint.net,代码行数:50,代码来源:DocumentWorkspace.cs

示例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);
            }
        }
开发者ID:herbqiao,项目名称:paint.net,代码行数:13,代码来源:SurfaceBox.cs

示例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);
        }
开发者ID:leejungho2,项目名称:xynotecgui,代码行数:11,代码来源:TgaFileType.cs

示例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;
        }
开发者ID:metadeta96,项目名称:openpdn,代码行数:70,代码来源:ResizeAction.cs


注:本文中的PaintDotNet.Surface.Clear方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。