Esempio n. 1
0
        private ImageResource CreateImageResource(int width, int height, double borderSize)
        {
            ImageResource resource2;
            double        x = borderSize / 2.0;

            using (ISurface <ColorBgra> surface = SurfaceAllocator.Bgra.Allocate(width, height, AllocationOptions.ZeroFillNotRequired))
            {
                using (IDrawingContext context = DrawingContext.FromSurface(surface, AlphaMode.Premultiplied, FactorySource.PerThread))
                {
                    RectDouble num4;
                    context.Clear(null);
                    RectDouble num2        = new RectDouble(x, x, width - borderSize, height - borderSize);
                    double     aspectRatio = this.AspectRatio;
                    if (aspectRatio > 1.0)
                    {
                        double num5 = num2.Height / aspectRatio;
                        num4 = new RectDouble(num2.X, num2.Y + ((num2.Height - num5) / 2.0), num2.Width, num5);
                    }
                    else if (aspectRatio < 1.0)
                    {
                        double num6 = num2.Width * aspectRatio;
                        num4 = new RectDouble(num2.X + ((num2.Width - num6) / 2.0), num2.Y, num6, num2.Height);
                    }
                    else
                    {
                        num4 = num2;
                    }
                    IDictionary <string, object> settingValues = (from p in this.RenderSettingPaths select KeyValuePairUtil.Create <string, object>(p, AppSettings.Instance[ConvertToolsPathToToolDefaultsPath(p)].Value)).ToDictionary <string, object>();
                    ShapeRenderParameters        renderParams  = new ShapeRenderParameters(num4.TopLeft, num4.BottomRight, new VectorDouble(1.0, 1.0), settingValues, null);
                    PropertyCollection           properties    = this.CreatePropertyCollection(renderParams);
                    this.OnSetImagePropertyCollectionValues(renderParams, properties);
                    IDictionary <object, object> propertyValues = (from p in properties select KeyValuePairUtil.Create <object, object>(p.GetOriginalNameValue(), p.Value)).ToDictionary <object, object>();
                    ShapeRenderParameters        parameters2    = new ShapeRenderParameters(num4.TopLeft, num4.BottomRight, new VectorDouble(1.0, 1.0), settingValues, propertyValues);
                    ShapeRenderData            data             = this.CreateImageRenderData(parameters2);
                    PaintDotNet.UI.Media.Brush brush            = SolidColorBrushCache.Get((ColorRgba128Float)ColorBgra.FromUInt32(0xff5894c1));
                    if (data.InteriorFill != null)
                    {
                        context.FillGeometry(data.InteriorFill.Geometry, SolidColorBrushCache.Get((ColorRgba128Float)Colors.White), null);
                        LinearGradientBrush brush2 = new LinearGradientBrush {
                            StartPoint = num4.TopLeft,
                            EndPoint   = num4.BottomRight
                        };
                        brush2.GradientStops.Add(new GradientStop((ColorRgba128Float)ColorBgra32.FromUInt32(0xffc0e1f3), 0.0));
                        brush2.GradientStops.Add(new GradientStop((ColorRgba128Float)ColorBgra32.FromUInt32(0xffe0eff8), 1.0));
                        context.FillGeometry(data.InteriorFill.Geometry, brush2, null);
                    }
                    if ((data.InteriorFill != null) && (data.OutlineDraw != null))
                    {
                        RenderLayer layer = RenderLayerCache.Get();
                        using (context.UseLayer(layer, null, data.InteriorFill.Geometry, AntialiasMode.PerPrimitive, null, 1.0, null, LayerOptions.None))
                        {
                            context.DrawGeometry(data.OutlineDraw.Geometry, SolidColorBrushCache.Get((ColorRgba128Float)Colors.White), 3.0);
                        }
                        RenderLayerCache.Return(layer);
                    }
                    if (data.OutlineDraw != null)
                    {
                        context.DrawGeometry(data.OutlineDraw.Geometry, brush, 1.0);
                    }
                    if (data.OutlineFill != null)
                    {
                        context.FillGeometry(data.OutlineFill.Geometry, brush, null);
                    }
                    string imageStringOverlay = this.ImageStringOverlay;
                    if (imageStringOverlay != string.Empty)
                    {
                        double     num7       = (width * 7.0) / 16.0;
                        double     fontSize   = UIUtil.ScaleWidth(num7);
                        TextLayout textLayout = new TextLayout(imageStringOverlay, "Arial", FontWeight.Normal, PaintDotNet.DirectWrite.FontStyle.Normal, FontStretch.Normal, fontSize)
                        {
                            ParagraphAlignment = ParagraphAlignment.Center,
                            TextAlignment      = PaintDotNet.DirectWrite.TextAlignment.Center,
                            MaxWidth           = width - 2,
                            MaxHeight          = height - 2
                        };
                        context.DrawTextLayout(new PointDouble(1.0, 1.0), textLayout, SolidColorBrushCache.Get((ColorRgba128Float)ColorBgra.FromUInt32(0xff5894c1)), DrawTextOptions.None);
                    }
                }
                surface.ConvertFromPremultipliedAlpha();
                using (System.Drawing.Bitmap bitmap = surface.CreateAliasedGdipBitmap())
                {
                    System.Drawing.Bitmap image = new System.Drawing.Bitmap(bitmap);
                    resource2 = ImageResource.FromImage(image);
                }
            }
            return(resource2);
        }
Esempio n. 2
0
        private void DrawToGraphics(Graphics g)
        {
            PointF tf4;
            Size   clientSize = base.ClientSize;
            PointF tf         = new PointF((this.position.X * this.dragAreaRect.Width) / ((float)clientSize.Width), (this.position.Y * this.dragAreaRect.Height) / ((float)clientSize.Height));
            PointF tf2        = new PointF(((float)clientSize.Width) / 2f, ((float)clientSize.Height) / 2f);
            PointF tf3        = new PointF(((1f + tf.X) * clientSize.Width) / 2f, ((1f + tf.Y) * clientSize.Height) / 2f);

            if (((-1f <= tf.X) && (tf.X <= 1f)) && ((-1f <= tf.Y) && (tf.Y <= 1f)))
            {
                tf4 = new PointF(((1f + tf.X) * clientSize.Width) / 2f, ((1f + tf.Y) * clientSize.Height) / 2f);
            }
            else
            {
                tf4 = new PointF(((1f + tf.X) * clientSize.Width) / 2f, ((1f + tf.Y) * clientSize.Height) / 2f);
                float introduced26 = Math.Abs(tf.X);
                if (introduced26 > Math.Abs(tf.Y))
                {
                    if (tf.X > 0f)
                    {
                        tf4.X = clientSize.Width - 1;
                        tf4.Y = ((1f + (tf.Y / tf.X)) * clientSize.Height) / 2f;
                    }
                    else
                    {
                        tf4.X = 0f;
                        tf4.Y = ((1f - (tf.Y / tf.X)) * clientSize.Height) / 2f;
                    }
                }
                else if (tf.Y > 0f)
                {
                    tf4.X = ((1f + (tf.X / tf.Y)) * clientSize.Width) / 2f;
                    tf4.Y = clientSize.Height - 1;
                }
                else
                {
                    tf4.X = ((1f - (tf.X / tf.Y)) * clientSize.Width) / 2f;
                    tf4.Y = 0f;
                }
            }
            using (g.UseCompositingMode(CompositingMode.SourceCopy))
            {
                g.Clear(this.BackColor);
            }
            using (g.UseCompositingMode(CompositingMode.SourceOver))
            {
                SizeInt32 num;
                Rectangle rectangle;
                if (this.staticImageUnderlay == null)
                {
                    goto Label_05A8;
                }
                if (this.cachedUnderlay != null)
                {
                    num = new SizeInt32(this.cachedUnderlay.Width, this.cachedUnderlay.Height);
                    goto Label_052E;
                }
                Image     reference = this.staticImageUnderlay.Reference;
                Rectangle srcRect   = new Rectangle(0, 0, reference.Width, reference.Height);
                SizeInt32 num2      = new SizeInt32(Math.Max(1, Math.Min(clientSize.Width - 4, srcRect.Width)), Math.Max(1, Math.Min(clientSize.Height - 4, srcRect.Height)));
                num = ThumbnailHelpers.ComputeThumbnailSize(reference.Size.ToSizeInt32(), Math.Min(num2.Width, num2.Height));
                this.cachedUnderlay = new Bitmap(num.Width, num.Height, PixelFormat.Format24bppRgb);
                ISurface <ColorBgra> surface = RendererBgra.Checkers(num).ToSurface();
                Bitmap    image    = surface.CreateAliasedGdipBitmap();
                Rectangle destRect = new Rectangle(0, 0, this.cachedUnderlay.Width, this.cachedUnderlay.Height);
                using (Graphics graphics = Graphics.FromImage(this.cachedUnderlay))
                {
                    graphics.CompositingMode = CompositingMode.SourceOver;
                    graphics.DrawImage(image, destRect, new Rectangle(0, 0, image.Width, image.Height), GraphicsUnit.Pixel);
                    Bitmap bitmap2 = reference as Bitmap;
                    if ((bitmap2 != null) && (bitmap2.PixelFormat == PixelFormat.Format32bppArgb))
                    {
                        BitmapData bitmapdata = bitmap2.LockBits(new Rectangle(new Point(0, 0), bitmap2.Size), ImageLockMode.ReadOnly, PixelFormat.Format32bppArgb);
                        try
                        {
                            using (SharedSurface <ColorBgra> surface2 = new SharedSurface <ColorBgra>(bitmapdata.Scan0, bitmapdata.Width, bitmapdata.Height, bitmapdata.Stride))
                            {
                                using (ISurface <ColorBgra> surface3 = surface2.ResizeSuperSampling(num).Parallelize <ColorBgra>(TilingStrategy.HorizontalSlices, 3, WorkItemQueuePriority.Normal).ToSurface())
                                {
                                    using (Bitmap bitmap3 = surface3.CreateAliasedGdipBitmap())
                                    {
                                        graphics.DrawImage(bitmap3, destRect, surface3.Bounds <ColorBgra>().ToGdipRectangle(), GraphicsUnit.Pixel);
                                        goto Label_051A;
                                    }
                                }
                            }
                        }
                        finally
                        {
                            bitmap2.UnlockBits(bitmapdata);
                        }
                    }
                    graphics.InterpolationMode = InterpolationMode.HighQualityBicubic;
                    RectangleF ef = RectangleF.Inflate(destRect, 0.5f, 0.5f);
                    graphics.DrawImage(reference, ef, srcRect, GraphicsUnit.Pixel);
                }
Label_051A:
                image.Dispose();
                image = null;
                surface.Dispose();
                surface = null;
Label_052E:
                rectangle = new Rectangle((clientSize.Width - num.Width) / 2, (clientSize.Height - num.Height) / 2, num.Width, num.Height);
                g.DrawImage(this.cachedUnderlay, rectangle, new Rectangle(0, 0, this.cachedUnderlay.Width, this.cachedUnderlay.Height), GraphicsUnit.Pixel);
                DropShadow.DrawOutside(g, rectangle, 2);
            }
Label_05A8:
            using (g.UsePixelOffsetMode(PixelOffsetMode.Half))
            {
                using (g.UseSmoothingMode(SmoothingMode.HighQuality))
                {
                    using (Pen pen = (Pen)Pens.Black.Clone())
                    {
                        pen.SetLineCap(LineCap.Round, LineCap.DiamondAnchor, DashCap.Flat);
                        pen.EndCap = LineCap.ArrowAnchor;
                        pen.Width  = 2f;
                        pen.Color  = SystemColors.ControlDark;
                        g.DrawLine(pen, tf2, tf4);
                    }
                    using (Pen pen2 = new Pen(Color.White))
                    {
                        pen2.SetLineCap(LineCap.DiamondAnchor, LineCap.DiamondAnchor, DashCap.Flat);
                        pen2.Width = 3f;
                        pen2.Color = Color.White;
                        g.DrawLine(pen2, tf3.X - 5f, tf3.Y, tf3.X + 5f, tf3.Y);
                        g.DrawLine(pen2, tf3.X, tf3.Y - 5f, tf3.X, tf3.Y + 5f);
                        pen2.Width = 2f;
                        pen2.Color = Color.Black;
                        g.DrawLine(pen2, tf3.X - 5f, tf3.Y, tf3.X + 5f, tf3.Y);
                        g.DrawLine(pen2, tf3.X, tf3.Y - 5f, tf3.X, tf3.Y + 5f);
                    }
                }
            }
        }