コード例 #1
0
ファイル: ImageUtil.cs プロジェクト: xw328907/Lottery2019
        private static void DrawSmallRaw(Person person, WIC.ImagingFactory wic, D2D.Factory d2dFactory,
                                         WIC.FormatConverter converter)
        {
            var whRate       = 1.0f * converter.Size.Width / converter.Size.Height;
            var smallRawSize = new Vector2(whRate * ImageDefines.SmallRawY, ImageDefines.SmallRawY);
            var scale        = ImageDefines.SmallRawY / converter.Size.Height;

            using (var wicBitmap = new WIC.Bitmap(wic,
                                                  (int)smallRawSize.X, (int)smallRawSize.Y,
                                                  WIC.PixelFormat.Format32bppPBGRA,
                                                  WIC.BitmapCreateCacheOption.CacheOnDemand))
                using (var target = new D2D.WicRenderTarget(d2dFactory,
                                                            wicBitmap, new D2D.RenderTargetProperties()))
                    using (var bmp = D2D.Bitmap.FromWicBitmap(target, converter))
                        using (var bmpBrush = new D2D.BitmapBrush(target, bmp))
                        {
                            target.BeginDraw();
                            target.Transform = Matrix3x2.Scaling(scale, scale);
                            target.DrawBitmap(bmp, 1.0f, D2D.BitmapInterpolationMode.Linear);
                            target.EndDraw();

                            using (var file = File.Create(person.SmallRawImage))
                            {
                                WicTools.SaveD2DBitmap(wic, wicBitmap, file);
                            }
                        }
        }
コード例 #2
0
ファイル: TextureBrushHandler.cs プロジェクト: mhusen/Eto
			protected override sd.Brush Create(sd.RenderTarget target)
			{
				var brush = new sd.BitmapBrush(target, Image.ToDx(target));
				brush.ExtendModeX = brush.ExtendModeY = sd.ExtendMode.Wrap;
				if (Transform != null)
					brush.Transform = Transform.ToDx();
				return brush;
			}
コード例 #3
0
ファイル: VisualBrushImpl.cs プロジェクト: healtech/Perspex
        public VisualBrushImpl(
            VisualBrush brush,
            RenderTarget target,
            Size targetSize)
        {
            var visual = brush.Visual;
            var layoutable = visual as ILayoutable;

            if (layoutable?.IsArrangeValid == false)
            {
                layoutable.Measure(Size.Infinity);
                layoutable.Arrange(new Rect(layoutable.DesiredSize));
            }

            var sourceRect = brush.SourceRect.ToPixels(layoutable.Bounds.Size);
            var destinationRect = brush.DestinationRect.ToPixels(targetSize);
            var bitmapSize = brush.TileMode == TileMode.None ? targetSize : destinationRect.Size;
            var scale = brush.Stretch.CalculateScaling(destinationRect.Size, sourceRect.Size);
            var translate = CalculateTranslate(brush, sourceRect, destinationRect, scale);
            var options = CompatibleRenderTargetOptions.None;

            using (var brt = new BitmapRenderTarget(target, options, bitmapSize.ToSharpDX()))
            {
                var renderer = new Renderer(brt);
                var transform = Matrix.CreateTranslation(-sourceRect.Position) *
                                Matrix.CreateScale(scale) *
                                Matrix.CreateTranslation(translate);

                Rect drawRect;

                if (brush.TileMode == TileMode.None)
                {
                    drawRect = destinationRect;
                    transform *= Matrix.CreateTranslation(destinationRect.Position);
                }
                else
                {
                    drawRect = new Rect(0, 0, destinationRect.Width, destinationRect.Height);
                }

                renderer.Render(visual, null, transform, drawRect);

                var result = new BitmapBrush(brt, brt.Bitmap);
                result.ExtendModeX = (brush.TileMode & TileMode.FlipX) != 0 ? ExtendMode.Mirror : ExtendMode.Wrap;
                result.ExtendModeY = (brush.TileMode & TileMode.FlipY) != 0 ? ExtendMode.Mirror : ExtendMode.Wrap;

                if (brush.TileMode != TileMode.None)
                {
                    result.Transform = SharpDX.Matrix3x2.Translation(
                        (float)destinationRect.X,
                        (float)destinationRect.Y);
                }

                PlatformBrush = result;
            }
        }
コード例 #4
0
ファイル: TextureBrushHandler.cs プロジェクト: sami1971/Eto
            protected override sd.Brush Create(sd.RenderTarget target)
            {
                var brush = new sd.BitmapBrush(target, Image.ToDx(target));

                brush.ExtendModeX = brush.ExtendModeY = sd.ExtendMode.Wrap;
                if (Transform != null)
                {
                    brush.Transform = Transform.ToDx();
                }
                return(brush);
            }
コード例 #5
0
ファイル: TileBrushImpl.cs プロジェクト: Arlorean/Perspex
        public TileBrushImpl(
            TileBrush brush,
            SharpDX.Direct2D1.RenderTarget target,
            Size targetSize)
        {
            var helper = new TileBrushImplHelper(brush, targetSize);
            if (!helper.IsValid)
                return;

            using (var intermediate = new BitmapRenderTarget(target, CompatibleRenderTargetOptions.None, helper.IntermediateSize.ToSharpDX()))
            {
                using (var ctx = new RenderTarget(intermediate).CreateDrawingContext())
                    helper.DrawIntermediate(ctx);

                PlatformBrush = new BitmapBrush(
                    target,
                    intermediate.Bitmap,
                    GetBitmapBrushProperties(brush),
                    GetBrushProperties(brush, helper.DestinationRect));
            }
        }
コード例 #6
0
            public void Initialize(D2D1.RenderTarget renderTarget, RawVector2 size, Block[] blocks)
            {
                var width  = (int)Math.Round(size.X);
                var height = (int)Math.Round(size.Y);
                var subLen = Math.Max(size.X, size.Y) / _density;
                var subRad = Math.PI * 2 / _densityTheta;
                var bitmap = new System.Drawing.Bitmap(width, height, System.Drawing.Imaging.PixelFormat.Format32bppPArgb);
                var color0 = _normalColor.ToSd();
                var color1 = _flashingColor.ToSd();

                DrawCheckerboard(bitmap, color0, color1, subLen, subRad);
                _bitmap0 = bitmap.ToD2D1Bitmap(renderTarget);
                DrawCheckerboard(bitmap, color1, color0, subLen, subRad);
                _bitmap1 = bitmap.ToD2D1Bitmap(renderTarget);
                bitmap.Dispose();
                _brush                   = new D2D1.BitmapBrush(renderTarget, _bitmap0);
                _brush.ExtendModeX       = _brush.ExtendModeY = D2D1.ExtendMode.Clamp;
                _brush.InterpolationMode = D2D1.BitmapInterpolationMode.NearestNeighbor;
                foreach (var block in blocks)
                {
                    block.Tag = Matrix3x2.Translation(block.ContentRect.Left, block.ContentRect.Top);
                }
            }
コード例 #7
0
ファイル: ImageUtil.cs プロジェクト: xw328907/Lottery2019
        private static void DrawPsd(Person person, WIC.ImagingFactory wic, D2D.Factory d2dFactory,
                                    WIC.FormatConverter converter)
        {
            using (var wicBitmap = new WIC.Bitmap(wic,
                                                  (int)ImageDefines.Size, (int)ImageDefines.Size,
                                                  WIC.PixelFormat.Format32bppPBGRA,
                                                  WIC.BitmapCreateCacheOption.CacheOnDemand))
                using (var target = new D2D.WicRenderTarget(d2dFactory,
                                                            wicBitmap, new D2D.RenderTargetProperties()))
                    using (var color = new D2D.SolidColorBrush(target, SexColor[person.Sex]))
                        using (var bmp = D2D.Bitmap.FromWicBitmap(target, converter))
                            using (var bmpBrush = new D2D.BitmapBrush(target, bmp))
                            {
                                target.BeginDraw();
                                var offset = (ImageDefines.Size - ImageDefines.RealSize) / 2;
                                bmpBrush.Transform = Matrix3x2.Scaling(
                                    ImageDefines.RealSize / bmp.Size.Width,
                                    ImageDefines.RealSize / (bmp.Size.Height - 497.0f))
                                                     * Matrix3x2.Translation(offset, offset);
                                target.FillEllipse(new D2D.Ellipse(
                                                       new Vector2(ImageDefines.Size / 2.0f, ImageDefines.Size / 2.0f),
                                                       ImageDefines.RealSize / 2.0f,
                                                       ImageDefines.RealSize / 2.0f),
                                                   bmpBrush);
                                target.DrawEllipse(new D2D.Ellipse(
                                                       new Vector2(ImageDefines.Size / 2.0f, ImageDefines.Size / 2.0f),
                                                       ImageDefines.RealSize / 2.0f,
                                                       ImageDefines.RealSize / 2.0f),
                                                   color, ImageDefines.LineWidth);
                                target.EndDraw();

                                using (var file = File.Create(person.PsdImage))
                                {
                                    WicTools.SaveD2DBitmap(wic, wicBitmap, file);
                                }
                            }
        }
コード例 #8
0
		/// <summary>
		/// 清除渲染使用的资源。
		/// </summary>
		public override void ClearResources()
		{
			base.ClearResources();
			if (this.brush != null)
			{
				this.brush.Dispose();
				this.brush = null;
			}
		}
コード例 #9
0
		/// <summary>
		/// 准备渲染拼图碎片。
		/// </summary>
		/// <param name="imageData">拼图使用的图片数据。</param>
		/// <param name="pieces">所有拼图碎片的集合。</param>
		/// <param name="rotatable">拼图碎片是否可以旋转。</param>
		/// <param name="ct">取消任务的通知。</param>
		public override void PrepareRender(byte[] imageData, JigsawPieceCollection pieces, bool rotatable,
			CancellationToken ct)
		{
			base.PrepareRender(imageData, pieces, rotatable, ct);
			if (this.brush == null)
			{
				this.brush = new BitmapBrush(this.RenderTarget, this.Image);
			}
			else
			{
				this.brush.Bitmap = this.Image;
			}
		}
コード例 #10
0
		/// <summary>
		/// 准备渲染拼图碎片。
		/// </summary>
		/// <param name="imageData">拼图使用的图片数据。</param>
		/// <param name="pieces">所有拼图碎片的集合。</param>
		/// <param name="rotatable">拼图碎片是否可以旋转。</param>
		/// <param name="ct">取消任务的通知。</param>
		public override void PrepareRender(byte[] imageData, JigsawPieceCollection pieces, bool rotatable,
			CancellationToken ct)
		{
			base.PrepareRender(imageData, pieces, rotatable, ct);
			ct.ThrowIfCancellationRequested();
			imageSize = new Size2((int)this.Image.Size.Width, (int)this.Image.Size.Height);
			using (Brush imageBrush = new BitmapBrush(this.DeviceContext, this.Image))
			{
				using (Bitmap1 source = DeviceManager.CreateBitmap(imageSize))
				{
					ct.ThrowIfCancellationRequested();
					// 设置特效的输入。
					bevelBaseEffect.SetInput(0, source, true);
					bevelEffect.SetInput(0, source, true);
					// 分别按黑色与白色创建拼图碎片特效。
					List<Geometry> blacks = new List<Geometry>();
					List<Geometry> whites = new List<Geometry>();
					foreach (JigsawPiece piece in pieces)
					{
						Geometry[] geoms = piece.OriginalPath.GetSourceGeometry();
						// 划分黑色与白色,他们分别是不相邻的。
						bool[] colors = piece.GetColors();
						for (int i = 0; i < colors.Length; i++)
						{
							if (colors[i])
							{
								blacks.Add(geoms[i]);
							}
							else
							{
								whites.Add(geoms[i]);
							}
						}
					}
					ct.ThrowIfCancellationRequested();
					pointSpecularEffect.LightPosition = new Vector3(0, 0, 0);
					this.images[0] = this.CreateImage(imageBrush, source, blacks, whites, ct);
					if (rotatable)
					{
						// 生成不同旋转角度的图像,使用不同的光照情况。
						pointSpecularEffect.LightPosition = new Vector3(0, imageSize.Height, 0);
						this.images[1] = this.CreateImage(imageBrush, source, blacks, whites, ct);
						pointSpecularEffect.LightPosition = new Vector3(imageSize.Width, imageSize.Height, 0);
						this.images[2] = this.CreateImage(imageBrush, source, blacks, whites, ct);
						pointSpecularEffect.LightPosition = new Vector3(imageSize.Width, 0, 0);
						this.images[3] = this.CreateImage(imageBrush, source, blacks, whites, ct);
					}
				}
			}
		}
コード例 #11
0
		/// <summary>
		/// 初始化笔刷。
		/// </summary>
		private void InitBrushes()
		{
			this.brush = new BitmapBrush(this.RenderTarget, null);
			this.shadowBrush = new BitmapBrush(this.RenderTarget, null);
			this.selectedBrush = new SolidColorBrush(this.RenderTarget, selectedColor);
			this.blackBrush = new SolidColorBrush(this.DeviceContext, Color.Black);
		}
コード例 #12
0
        internal override void Create()
        {
            if (NativeBrush != null)
                NativeBrush.Dispose();

            m_bitmap.Create();
            var props = new BitmapBrushProperties();
            props.InterpolationMode = BitmapInterpolationMode.Linear;
            NativeBrush = new BitmapBrush(Owner.D2dRenderTarget, m_bitmap.NativeBitmap, props);

            ExtendModeX = m_extendModeX;
            ExtendModeY = m_extendModeY;
            InterpolationMode = D2dBitmapInterpolationMode.Linear;
            Location = m_location;
            Bitmap = m_bitmap;
        }
コード例 #13
0
ファイル: AssetManager.cs プロジェクト: sleepless1/GameSharp
 BrushAsset IAssetManager.LoadBrush(Bitmap bitmap, BitmapBrushProperties? bitmapBrushProps, BrushProperties? brushProps)
 {
     /// TODFO: THis needs to be finished!!!!
     BitmapBrush brush = new BitmapBrush(RenderTarget2D, bitmap, bitmapBrushProps, brushProps);
     return new BrushAsset(brush);
 }