public static Surface CreateThumbnail(Surface sourceSurface, GeometryList maskGeometry, RectInt32 maskBounds, int thumbSideLength) { Surface dst = new Surface(ThumbnailHelpers.ComputeThumbnailSize(sourceSurface.Size <ColorBgra>(), thumbSideLength)); dst.Clear(ColorBgra.Transparent); sourceSurface.ResizeFant(dst.Size <ColorBgra>()).Parallelize <ColorBgra>(TilingStrategy.HorizontalSlices, 5, WorkItemQueuePriority.Normal).Render <ColorBgra>(dst); Surface surface = new Surface(dst.Size <ColorBgra>()); surface.Clear(ColorBgra.Black); using (PdnGraphicsPath path = new PdnGraphicsPath()) { path.AddGeometryList(maskGeometry); double scaleX = (maskBounds.Width == 0) ? 0.0 : (((double)dst.Width) / ((double)maskBounds.Width)); double scaleY = (maskBounds.Height == 0) ? 0.0 : (((double)dst.Height) / ((double)maskBounds.Height)); Matrix3x2Double m = Matrix3x2Double.Translation((double)-maskBounds.X, (double)-maskBounds.Y) * Matrix3x2Double.Scaling(scaleX, scaleY); using (RenderArgs args = new RenderArgs(surface)) { args.Graphics.SmoothingMode = SmoothingMode.AntiAlias; using (Matrix matrix = m.ToGdipMatrix()) { args.Graphics.Transform = matrix; } args.Graphics.FillPath(Brushes.White, (GraphicsPath)path); args.Graphics.DrawPath(Pens.White, (GraphicsPath)path); } } new IntensityMaskOp().Apply(surface, dst, surface); RendererBgra.Checkers(dst.Size <ColorBgra>()).Render <ColorBgra>(dst); CompositionOps.Normal.Static.Apply(dst, dst, surface); surface.Dispose(); surface = null; int recommendedExtent = DropShadow.GetRecommendedExtent(dst.Size <ColorBgra>()); ShadowDecorationRenderer renderer = new ShadowDecorationRenderer(dst, recommendedExtent); Surface surface3 = new Surface(renderer.Size <ColorBgra>()); renderer.Render <ColorBgra>(surface3); return(surface3); }
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); } } } }